:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --sidebar: #f0f4f9;
  --border: #dadce0;
  --text: #202124;
  --muted: #5f6368;
  --primary: #1a73e8;
  --primary-hover: #1765cc;
  --primary-soft: #e8f0fe;
  --danger: #c5221f;
  --danger-bg: #fce8e6;
  --ok: #137333;
  --ok-bg: #e6f4ea;
  --shadow: 0 1px 2px rgba(60, 64, 67, 0.15), 0 1px 3px rgba(60, 64, 67, 0.1);
  --radius: 12px;
  --sidebar-w: 260px;
  --topbar-h: 64px;
  --font: Inter, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
body.app-locked {
  overflow: hidden;
}
button, input { font: inherit; }
a { color: var(--primary); }
[hidden] { display: none !important; }

svg { width: 20px; height: 20px; fill: currentColor; flex-shrink: 0; }

/* Login */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, #e8f0fe 0%, var(--bg) 45%, #fff 100%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-logo { width: 120px; display: block; margin: 0 auto 16px; }
.login-card h1 { margin: 0; font-size: 18px; font-weight: 600; text-align: center; }
.login-sub { margin: 4px 0 24px; text-align: center; color: var(--muted); font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 12px; font-weight: 500; color: var(--muted); }
.field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  outline: none;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, box-shadow 0.15s;
}
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); box-shadow: var(--shadow); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f1f3f4; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); cursor: pointer;
  display: inline-grid; place-items: center;
}
.icon-btn:hover { background: #e8eaed; color: var(--text); }

.alert, .banner {
  padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px;
}
.alert, .banner.err { background: var(--danger-bg); color: var(--danger); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }

/* Drive shell */
.drive {
  display: flex;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(32, 33, 36, 0.45); z-index: 40;
}
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  height: 100%;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  z-index: 50;
  overflow: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 20px;
}
.sidebar-brand img { width: 36px; height: 36px; object-fit: contain; }
.sidebar-brand strong { display: block; font-size: 14px; }
.sidebar-brand span { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; border: 0; background: transparent;
  padding: 10px 14px; border-radius: 999px;
  color: var(--text); font-weight: 500; cursor: pointer; text-align: left;
}
.nav-item:hover { background: rgba(26, 115, 232, 0.08); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.nav-item.subtle { color: var(--muted); font-weight: 400; font-size: 13px; margin-top: 8px; }

.sidebar-foot {
  padding: 12px 10px 4px;
  border-top: 1px solid var(--border);
}
.storage-head {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--muted); margin-bottom: 8px;
}
.storage-track {
  height: 4px; background: #dadce0; border-radius: 999px; overflow: hidden;
}
.storage-fill {
  height: 100%; width: 0; background: var(--primary);
  border-radius: 999px; transition: width 0.35s ease;
}
.storage-text { font-size: 11px; color: var(--muted); margin: 8px 0 0; }

.main {
  flex: 1; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.menu-btn { display: none; }

.search-box {
  flex: 1; max-width: 720px;
  display: flex; align-items: center; gap: 10px;
  background: #f1f3f4; border-radius: 999px;
  padding: 0 16px; height: 44px;
}
.search-box svg { color: var(--muted); width: 20px; height: 20px; }
.search-box input {
  flex: 1; border: 0; background: transparent; outline: none;
  font-size: 15px; min-width: 0;
}

.topbar-actions {
  display: flex; align-items: center; gap: 10px; margin-left: auto;
}
.user-menu {
  display: flex; align-items: center; gap: 8px;
  padding-left: 8px; border-left: 1px solid var(--border);
}
.user-email {
  font-size: 13px; color: var(--muted);
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.workspace {
  flex: 1; display: flex; flex-direction: column;
  padding: 16px 20px 24px; min-height: 0;
  overflow: hidden;
}

.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 12px;
}
.breadcrumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  font-size: 22px; font-weight: 400; min-width: 0;
}
.breadcrumbs button {
  border: 0; background: transparent; padding: 4px 6px;
  border-radius: 6px; cursor: pointer; color: var(--text);
  font: inherit; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.breadcrumbs button:hover { background: #e8eaed; }
.breadcrumbs .sep { color: var(--muted); user-select: none; }
.breadcrumbs .current { font-weight: 500; pointer-events: none; }

.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.upload-btn { cursor: pointer; margin: 0; }
.upload-split { display: flex; gap: 6px; flex-wrap: wrap; }

.content {
  flex: 1; min-height: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: border-color 0.2s, background 0.2s;
}
.content.drag {
  border-color: var(--primary);
  background: #f8fbff;
}

.selection-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary);
  font-size: 13px; font-weight: 500;
}
.table-head {
  display: grid;
  grid-template-columns: 36px minmax(180px, 1fr) 160px 100px 88px;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 12px; font-weight: 500; color: var(--muted);
  background: #fafbfc;
  align-items: center;
}
.check-cell {
  display: grid; place-items: center;
  margin: 0; cursor: pointer;
}
.check-cell input {
  width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer;
}
.file-row {
  display: grid;
  grid-template-columns: 36px minmax(180px, 1fr) 160px 100px 88px;
  gap: 12px;
  align-items: center;
  padding: 6px 20px;
  border-bottom: 1px solid #f1f3f4;
  animation: fade-in 0.2s ease both;
}
.file-row.selected { background: #e8f0fe; }
.file-row:hover { background: #f8f9fa; }
.file-row.selected:hover { background: #e8f0fe; }
.file-icon {
  width: 24px; height: 24px;
  display: grid; place-items: center; flex-shrink: 0;
  background: none !important; border-radius: 0;
  color: #5f6368;
}
.file-icon.folder { color: #5f6368; }
.file-icon.image { color: #1a73e8; }
.file-icon.pdf { color: #d93025; }
.file-icon.video { color: #a142f4; }
.file-icon.sheet { color: #188038; }
.file-icon.doc { color: #1a73e8; }
.file-icon svg { width: 22px; height: 22px; }
.file-name-cell {
  display: flex; align-items: center; gap: 10px;
  min-width: 0; border: 0; background: transparent;
  text-align: left; cursor: pointer; padding: 4px 0;
  font: inherit; color: inherit;
}
.file-list {
  list-style: none; margin: 0; padding: 0;
  overflow: auto; flex: 1; min-height: 0;
}
.file-row:last-child { border-bottom: 0; }

.upload-panel {
  position: fixed; right: 24px; bottom: 24px; z-index: 80;
  width: min(360px, calc(100vw - 32px));
  background: #fff; border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,0.18);
  overflow: hidden;
}
.upload-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: #f8f9fa; border-bottom: 1px solid var(--border);
}
.upload-panel-head strong { font-size: 13px; font-weight: 500; }
.upload-list { list-style: none; margin: 0; padding: 8px 0; max-height: 240px; overflow: auto; }
.upload-item { padding: 8px 14px; }
.upload-item-name {
  font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.upload-item-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.upload-item-meta.ok { color: var(--ok); }
.upload-item-meta.err { color: var(--danger); }
.upload-bar {
  height: 4px; background: #e8eaed; border-radius: 999px; overflow: hidden; margin-top: 6px;
}
.upload-bar > span {
  display: block; height: 100%; width: 0; background: var(--primary);
  transition: width 0.15s linear;
}
.file-meta { min-width: 0; }
.file-title {
  font-weight: 500; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.col-date, .col-size, .cell-muted {
  font-size: 13px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cell-meta-mobile { display: none; }
.mobile-only { display: none; }
.row-actions {
  display: flex; justify-content: flex-end; gap: 4px; opacity: 0;
  transition: opacity 0.15s;
}
.file-row:hover .row-actions { opacity: 1; }
.row-actions .icon-btn { width: 32px; height: 32px; }

.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; color: var(--muted); padding: 48px 24px;
}
.empty-state svg { width: 56px; height: 56px; color: #bdc1c6; }
.empty-state p { margin: 0; font-size: 15px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #323232; color: #fff; padding: 12px 20px;
  border-radius: 8px; font-size: 13px; z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

/* Modals */
.modal {
  border: 0; padding: 0; background: transparent;
  max-width: none; width: auto;
}
.modal::backdrop { background: rgba(32, 33, 36, 0.6); }
.modal-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: min(440px, calc(100vw - 32px));
  box-shadow: 0 8px 28px rgba(0,0,0,0.18);
  margin: auto;
}
.modal-sm { width: min(400px, calc(100vw - 32px)); }
.ui-dialog-icon {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; margin-bottom: 12px;
}
.ui-dialog-icon svg { width: 22px; height: 22px; }
.ui-dialog-icon.danger { background: #fce8e6; color: #c5221f; }
.ui-dialog-icon.info { background: #e8f0fe; color: #1a73e8; }
.ui-dialog-icon.warn { background: #fef7e0; color: #e37400; }
.btn-danger {
  background: #d93025; color: #fff;
}
.btn-danger:hover { background: #b3261e; box-shadow: var(--shadow); }
#ui-dialog-form .modal-header {
  flex-direction: column; align-items: flex-start; gap: 0;
}
#ui-dialog-form .modal-header h2 { margin-top: 0; }
.modal-xl { width: min(960px, calc(100vw - 24px)); max-height: calc(100vh - 48px); display: flex; flex-direction: column; }
.modal-header-actions { display: flex; align-items: center; gap: 6px; }
.modal-xl .status-body { overflow: auto; flex: 1; min-height: 0; }

.status-body { display: flex; flex-direction: column; gap: 20px; }
.status-loading { margin: 24px 0; color: var(--muted); text-align: center; }
.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.status-card {
  background: #f8f9fa;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.status-card .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.status-card .value { font-size: 20px; font-weight: 600; line-height: 1.2; }
.status-card .sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.status-section h3 {
  margin: 0 0 10px; font-size: 14px; font-weight: 600;
}
.meter {
  height: 6px; background: #e8eaed; border-radius: 999px; overflow: hidden; margin-top: 8px;
}
.meter > span {
  display: block; height: 100%; background: var(--primary); border-radius: 999px;
}
.meter.warn > span { background: #f9ab00; }
.meter.crit > span { background: #d93025; }
.status-meta {
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  font-size: 12px; color: var(--muted); margin-bottom: 4px;
}
.status-meta strong { color: var(--text); font-weight: 500; }

@media (max-width: 900px) {
  .status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .status-grid { grid-template-columns: 1fr; }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h2 { margin: 0; font-size: 18px; font-weight: 500; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px;
}
.modal-copy { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.code-block {
  display: block; padding: 12px; background: #f1f3f4;
  border-radius: 8px; font-size: 12px; word-break: break-all;
}

.admin-form {
  display: grid;
  grid-template-columns: 1fr 100px auto;
  gap: 12px; align-items: end;
  margin-bottom: 16px;
}
.admin-form .field { margin: 0; }
.field-narrow input { text-align: center; }

.table-scroll { overflow: auto; max-height: 360px; border: 1px solid var(--border); border-radius: 8px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  padding: 10px 14px; text-align: left; border-bottom: 1px solid #f1f3f4;
}
.data-table th {
  background: #fafbfc; font-weight: 500; color: var(--muted);
  position: sticky; top: 0;
}
.data-table tr:hover td { background: #f8f9fa; }
.data-table td:last-child { text-align: right; white-space: nowrap; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 960px) {
  .table-head { display: none; }
  .file-row {
    grid-template-columns: 36px 1fr auto;
    grid-template-areas:
      "check name actions"
      "check meta meta";
    padding: 12px 16px;
  }
  .check-cell { grid-area: check; }
  .file-name-cell { grid-area: name; }
  .row-actions { grid-area: actions; opacity: 1; }
  .cell-date, .cell-size { display: none; }
  .cell-meta-mobile {
    display: block;
    grid-area: meta;
    font-size: 12px; color: var(--muted); padding-left: 0;
  }
  .mobile-only { display: block; }
  .user-email { display: none; }
}

@media (max-width: 768px) {
  .menu-btn { display: inline-grid; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { padding: 0 12px; }
  .workspace { padding: 12px; }
  .breadcrumbs { font-size: 18px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .btn { flex: 1; }
  .admin-form { grid-template-columns: 1fr; }
}
