:root {
  /* Graphite emerald dark theme */
  --bg: #0f1318;
  --panel: #171c22;
  --panel-2: #1a2028;
  --border: #2a313a;
  --border-faint: #1d232a;
  --text: #e8ecef;
  --muted: #8a949e;
  --accent: #10b981;
  --accent-hover: #0d9f72;
  --accent-text: #04231a;
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);
  --danger-border: rgba(248, 113, 113, 0.4);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --radius: 10px;
  --radius-sm: 7px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(16, 185, 129, 0.3); }

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: 16px;
  min-width: 0;
}
.bucket-name {
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 9px;
  border-radius: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.user { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.avatar { width: 28px; height: 28px; border-radius: 50%; }
.user-name { color: var(--muted); white-space: nowrap; }
.logout-form { margin: 0; }

/* ---- Toolbar ---- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.breadcrumb { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.crumb { color: var(--accent); text-decoration: none; }
.crumb:hover { text-decoration: underline; }
.crumb-sep { color: var(--muted); }
.toolbar-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ---- Buttons ---- */
.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--panel-2); border-color: #36404b; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 500; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-danger { color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger-border); }

/* ---- Content / listing ---- */
.content {
  margin: 0 20px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  min-height: 240px;
  overflow-x: auto;
}
.listing { width: 100%; border-collapse: collapse; }
.listing thead th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.col-size { width: 110px; }
.col-modified { width: 190px; }
.col-actions { width: 230px; }
.listing tbody td { padding: 10px 16px; border-bottom: 1px solid var(--border-faint); }
.listing tbody tr:last-child td { border-bottom: none; }
.row { transition: background 0.12s; }
.row:hover { background: var(--panel-2); }
.col-size, .col-modified { color: var(--muted); white-space: nowrap; }
.icon { margin-right: 8px; }
.col-name { word-break: break-word; }
.name-link { color: var(--text); text-decoration: none; cursor: pointer; }
.name-link:hover { color: var(--accent); }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* ---- Image thumbnails ---- */
.name-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.fname { word-break: break-word; }
.thumb {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  cursor: zoom-in;
  transition: border-color 0.15s;
}
.thumb:hover { border-color: var(--accent); }

.empty, .loading {
  padding: 48px;
  text-align: center;
  color: var(--muted);
}

/* ---- Drop hint ---- */
.drop-hint {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--accent);
  background: rgba(16, 185, 129, 0.08);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  pointer-events: none;
  z-index: 5;
}
.drop-hint.active { display: flex; }

/* ---- Uploads panel ---- */
.uploads {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 320px;
  max-width: calc(100vw - 24px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 40;
}
.uploads-header {
  padding: 10px 14px;
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.upload-row { padding: 10px 14px; border-bottom: 1px solid var(--border-faint); }
.upload-row:last-child { border-bottom: none; }
.upload-name { font-size: 13px; margin-bottom: 6px; word-break: break-all; }
.upload-bar { height: 6px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.upload-bar-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.upload-status { font-size: 11px; color: var(--muted); margin-top: 4px; }
.upload-done .upload-bar-fill { background: var(--accent); }
.upload-error .upload-bar-fill { background: var(--danger); }

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #0b1f17;
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast-error { background: #2a1414; border-color: var(--danger-border); }

/* ---- Lightbox (large image view) ---- */
body.no-scroll { overflow: hidden; }
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lightbox[hidden] { display: none; }
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  cursor: zoom-out;
}
.lightbox-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 92vw;
  max-height: 92vh;
}
.lightbox-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
}
.lightbox-title { font-size: 14px; word-break: break-all; min-width: 0; }
.lightbox-actions { display: flex; gap: 8px; flex-shrink: 0; }
.lightbox-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
}
.lightbox-img {
  max-width: 92vw;
  max-height: 78vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--panel);
}
.lightbox-img:not([src]) { display: none; }
.lightbox-loading { color: var(--muted); font-size: 14px; }

/* ---- Login ---- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(16, 185, 129, 0.12), transparent 60%),
    var(--bg);
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 40px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-logo { font-size: 40px; }
.login-card h1 { margin: 8px 0 4px; font-size: 22px; font-weight: 500; }
.login-sub { color: var(--muted); margin: 0 0 24px; }
.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  justify-content: center;
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: #1f2933;
  text-decoration: none;
  font-weight: 500;
}
.google-btn:hover { background: #f1f3f5; }
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-size: 13px;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); }

/* ---- Responsive ---- */
@media (max-width: 760px) {
  .topbar { padding: 10px 14px; }
  .brand { font-size: 15px; }
  .bucket-name { max-width: 130px; }
  .user-name { display: none; }
  .toolbar { padding: 10px 14px; align-items: stretch; }
  .breadcrumb { width: 100%; }
  .toolbar-actions { width: 100%; justify-content: flex-end; }
  .content { margin: 0 10px 12px; }
  .listing thead th, .listing tbody td { padding: 10px 12px; }
  /* Modified date is the lowest-priority column on small screens. */
  .col-modified { display: none; }
  .col-actions { width: auto; }
}

@media (max-width: 480px) {
  .btn { padding: 8px 12px; }
  .btn-sm { padding: 6px 9px; }
  /* Drop size too; the file name + actions are what matter on phones. */
  .col-size { display: none; }
  .actions { gap: 5px; }
  .uploads { right: 10px; left: 10px; bottom: 10px; width: auto; }
  .login-card { padding: 28px 22px; }
}
