:root {
    --bg: #FFFFFF;
    --bg-hover: #F5F5F5;
    --bg-active: #EDF5FF;
    --border: #E0E0E0;
    --border-light: #EEEEEE;
    --text: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    --accent: #2D7FF9;
    --accent-hover: #1A6CF0;
    --accent-light: #EDF5FF;
    --danger: #EF4444;
    --danger-light: #FEF2F2;
    --success: #10B981;
    --success-light: #ECFDF5;
    --warning: #F59E0B;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius: 6px;
    --radius-lg: 8px;
  }

  * { margin: 0; padding: 0; box-sizing: border-box; }

  body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
  }

  /* ===== LAYOUT ===== */
  .app {
    display: flex;
    flex-direction: column;
    height: 100vh;
  }

  /* ===== AUTH SCREEN ===== */
  .auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: #FAFAFA;
  }

  .auth-card {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 380px;
    text-align: center;
  }

  .auth-icon {
    font-size: 40px;
    margin-bottom: 16px;
  }

  .auth-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
  }

  .auth-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 24px;
  }

  .auth-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
    margin-bottom: 12px;
  }

  .auth-input:focus { border-color: var(--accent); }

  .auth-input.code-input {
    text-align: center;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: 8px;
    padding: 14px;
  }

  .auth-btn {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 12px;
  }

  .auth-btn:hover { background: var(--accent-hover); }
  .auth-btn:disabled { background: #CCC; cursor: not-allowed; }

  .auth-error {
    color: var(--danger);
    font-size: 12px;
    margin-bottom: 12px;
    display: none;
  }

  .auth-error.visible { display: block; }

  .auth-link {
    color: var(--accent);
    font-size: 12px;
    cursor: pointer;
    text-decoration: none;
  }

  .auth-link:hover { text-decoration: underline; }

  .auth-loading {
    color: var(--text-muted);
    font-size: 13px;
    padding: 20px;
  }

  .spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-bottom: 12px;
  }

  @keyframes spin {
    to { transform: rotate(360deg); }
  }

  /* ===== TOOLBAR ===== */
  .toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
  }

  .breadcrumb {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }

  .breadcrumb-item {
    padding: 4px 8px;
    border-radius: var(--radius);
    cursor: pointer;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
    transition: background 0.15s;
  }

  .breadcrumb-item:hover { background: var(--bg-hover); }
  .breadcrumb-item.current { color: var(--text); cursor: default; }
  .breadcrumb-item.current:hover { background: transparent; }

  .breadcrumb-sep {
    color: var(--text-muted);
    font-size: 11px;
    flex-shrink: 0;
  }

  .toolbar-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
  }

  .btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    font-family: inherit;
  }

  .btn:hover { background: var(--bg-hover); border-color: #CCC; }
  .btn:active { transform: scale(0.98); }

  .btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
  .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

  .btn-danger { color: var(--danger); border-color: var(--danger); }
  .btn-danger:hover { background: var(--danger-light); }

  .btn-icon { padding: 6px 8px; border: none; background: transparent; }
  .btn-icon:hover { background: var(--bg-hover); }

  .btn .icon { font-size: 14px; line-height: 1; }

  .toolbar-dropdown {
    position: relative;
    display: inline-block;
  }
  .toolbar-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    min-width: 200px;
    z-index: 100;
    padding: 4px 0;
  }
  .toolbar-dropdown-menu.active { display: block; }
  .toolbar-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
  }
  .toolbar-dropdown-item:hover { background: var(--bg-hover); }
  .toolbar-dropdown-item .icon { font-size: 14px; line-height: 1; }

  /* ===== NESTED FOLDERS ===== */
  .nested-items {
    display: none;
  }

  .nested-items.expanded {
    display: table-row;
  }

  .nested-row {
    background: var(--bg-hover);
  }

  .nested-row .file-name-cell {
    padding-left: 40px;
  }

  .expand-btn {
    cursor: pointer;
    user-select: none;
    display: inline-block;
    width: 18px;
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
    transition: color 0.15s;
  }

  .expand-btn:hover {
    color: var(--accent);
  }

  .expand-btn.expanded {
    color: var(--text);
  }

  /* ===== MAIN CONTENT ===== */
  .content {
    flex: 1;
    overflow-y: auto;
    position: relative;
  }

  /* ===== DROP ZONE OVERLAY ===== */
  .drop-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(45, 127, 249, 0.06);
    border: 2px dashed var(--accent);
    border-radius: var(--radius-lg);
    z-index: 100;
    align-items: center;
    justify-content: center;
    margin: 8px;
  }

  .drop-overlay.active { display: flex; }

  .drop-overlay-text {
    background: var(--accent);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-md);
  }

  /* ===== TABLE ===== */
  .file-table {
    width: 100%;
    border-collapse: collapse;
  }

  .file-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #FAFAFA;
  }

  .file-table th {
    padding: 6px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    user-select: none;
  }

  .file-table td {
    padding: 0 16px;
    border-bottom: 1px solid var(--border-light);
    height: 40px;
    vertical-align: middle;
  }

  .file-row { cursor: pointer; transition: background 0.1s; }
  .file-row:hover { background: var(--bg-hover); }
  .file-row.selected { background: var(--bg-active); }

  /* Drop target highlight when dragging files onto a folder row */
  .file-row.drop-target {
    background: var(--accent-light);
    outline: 2px solid var(--accent);
    outline-offset: -2px;
  }

  .file-name-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
  }

  .file-icon { font-size: 18px; flex-shrink: 0; width: 24px; text-align: center; }

  .file-name {
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .file-size, .file-date {
    color: var(--text-secondary);
    font-size: 12px;
    white-space: nowrap;
  }

  .file-actions { opacity: 0; display: flex; gap: 2px; transition: opacity 0.1s; }
  .file-row:hover .file-actions { opacity: 1; }

  .file-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all 0.1s;
  }

  .file-action-btn:hover { background: var(--bg-hover); color: var(--text); }
  .file-action-btn.delete:hover { background: var(--danger-light); color: var(--danger); }

  /* ===== EMPTY STATE ===== */
  .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
  }

  .empty-state .icon { font-size: 40px; margin-bottom: 12px; opacity: 0.5; }
  .empty-state .title { font-size: 14px; font-weight: 500; color: var(--text-secondary); margin-bottom: 4px; }
  .empty-state .subtitle { font-size: 12px; }

  /* ===== PREVIEW PANEL ===== */
  .preview-panel {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.6);
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
  }

  .preview-panel.active { display: flex; }

  .preview-container {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 900px;
    height: 85%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
  }

  .preview-filename { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .preview-actions { display: flex; gap: 6px; }

  .preview-body {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F5F5F5;
  }

  .preview-body iframe { width: 100%; height: 100%; border: none; }
  .preview-body img { max-width: 100%; max-height: 100%; object-fit: contain; }

  .preview-unsupported { text-align: center; color: var(--text-muted); padding: 40px; }

  /* Crop overlay */
  #cropBody canvas { display: block; }
  #cropSelection { z-index: 10; }
  .crop-dim-overlay { position: absolute; background: rgba(0,0,0,0.4); pointer-events: none; z-index: 5; }
  .preview-unsupported .icon { font-size: 48px; margin-bottom: 12px; }

  /* ===== MODAL ===== */
  .modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0,0,0,0.4);
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(1px);
  }

  .modal-overlay.active { display: flex; }

  .modal {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 360px;
    overflow: hidden;
  }

  .modal-header { padding: 16px 20px 0; font-weight: 600; font-size: 15px; }

  .modal-body { padding: 12px 20px 20px; }

  .modal-body input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
  }

  .modal-body input:focus { border-color: var(--accent); }

  .modal-body .helper-text { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

  .modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 16px; }

  /* ===== TOAST ===== */
  .toast-container {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .toast {
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: toastIn 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .toast.success { background: var(--success); color: white; }
  .toast.error { background: var(--danger); color: white; }
  .toast.info { background: var(--accent); color: white; }

  @keyframes toastIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* ===== LOADING ===== */
  .loading-bar {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--accent);
    animation: loadingSlide 1s ease infinite;
    display: none;
    z-index: 50;
  }

  .loading-bar.active { display: block; }

  @keyframes loadingSlide {
    0% { transform: translateX(-100%); }
    50% { transform: translateX(0%); }
    100% { transform: translateX(100%); }
  }

  /* ===== CONTEXT MENU ===== */
  .context-menu {
    display: none;
    position: fixed;
    z-index: 2500;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    padding: 4px 0;
    overflow: hidden;
  }

  .context-menu.active { display: block; }

  .context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.1s;
    color: var(--text);
  }

  .context-menu-item:hover { background: var(--bg-hover); }
  .context-menu-item.danger { color: var(--danger); }
  .context-menu-item.danger:hover { background: var(--danger-light); }
  .context-menu-divider { border-top: 1px solid var(--border-light); margin: 4px 0; }

  /* ===== UPLOAD PROGRESS ===== */
  .upload-progress {
    display: none;
    position: fixed;
    bottom: 16px;
    left: 16px;
    z-index: 3000;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 14px 18px;
    min-width: 280px;
  }

  .upload-progress.active { display: block; }

  .upload-progress-title { font-weight: 600; font-size: 13px; margin-bottom: 8px; }

  .upload-progress-bar {
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 6px;
  }

  .upload-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s;
    width: 0%;
  }

  .upload-progress-text { font-size: 11px; color: var(--text-muted); }

  /* ===== SCROLLBAR ===== */
  .content::-webkit-scrollbar { width: 6px; }
  .content::-webkit-scrollbar-track { background: transparent; }
  .content::-webkit-scrollbar-thumb { background: #DDD; border-radius: 3px; }
  .content::-webkit-scrollbar-thumb:hover { background: #CCC; }

  #fileInput { display: none; }

  /* ===== HIDE SECTIONS ===== */
  .hidden { display: none !important; }