/* Drive Portal — design tokens.
   Mobile-first; the wider layout is layered on at 720px. Both themes are real
   themes, not an inversion: dark uses its own surface ramp. */
:root {
  color-scheme: light dark;      /* scrollbars and native controls follow the theme */

  --bg:            #f6f7f9;
  --surface:       #ffffff;
  --surface-2:     #fafbfc;
  --border:        #e4e7ec;
  --border-strong: #d3d8e0;

  --text:          #101828;
  --text-2:        #5a6474;
  --text-3:        #8a94a6;

  --accent:        #2f5fe0;
  --accent-hover:  #2850c4;
  --accent-soft:   #eef2fe;
  --on-accent:     #ffffff;

  --lock-bg:       #fdf3e3;
  --lock-fg:       #92620d;
  --ok-bg:         #e8f6ed;
  --ok-fg:         #1a6b3c;
  --err-bg:        #fdecec;
  --err-fg:        #a3271f;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 12px -2px rgba(16, 24, 40, .08), 0 2px 4px -2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 20px 40px -12px rgba(16, 24, 40, .22);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --header-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0e1117;
    --surface:       #161b23;
    --surface-2:     #1b212b;
    --border:        #262e3a;
    --border-strong: #333d4d;

    --text:          #e8ecf3;
    --text-2:        #9aa5b6;
    --text-3:        #6e7a8c;

    --accent:        #5b86f5;
    --accent-hover:  #6f95f7;
    --accent-soft:   #1c2740;
    --on-accent:     #0b0f16;

    --lock-bg:       #3a2c12;
    --lock-fg:       #f0c163;
    --ok-bg:         #14301f;
    --ok-fg:         #6fd39a;
    --err-bg:        #3a1c1a;
    --err-fg:        #f5928a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, .5);
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ---------- header ---------- */
header {
  height: var(--header-h);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
header h1 {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -.01em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
}
header h1::before {
  content: "";
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #9b5cf0));
  box-shadow: var(--shadow-sm);
}
header a { color: var(--text-2); text-decoration: none; font-size: 13px; }
header a:hover { color: var(--text); }
header .who {
  font-size: 13px;
  color: var(--text-2);
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main { max-width: 1080px; margin: 0 auto; padding: 16px 14px 40px; }
@media (min-width: 720px) {
  header { padding: 0 24px; }
  header h1 { font-size: 16px; }
  main { padding: 24px; }
}

/* ---------- surfaces ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.card h2 {
  font-size: 14px;
  font-weight: 620;
  letter-spacing: -.005em;
  margin: 0 0 12px;
}
.hint { font-size: 13px; color: var(--text-2); margin: 0 0 10px; }
.hint b { color: var(--text); font-weight: 600; }

/* ---------- form controls ---------- */
label {
  display: block;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text-2);
  margin: 12px 0 5px;
}
input, select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font: inherit;
  font-size: 16px;              /* 16px keeps iOS from zooming on focus */
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: var(--text-3); }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
input[type="search"]::-webkit-search-cancel-button { display: none; }

button {
  padding: 10px 16px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .06s, opacity .15s;
}
button:hover { background: var(--accent-hover); }
button:active { transform: scale(.985); }
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}
button:disabled { opacity: .45; cursor: default; transform: none; }
button.ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
button.ghost:hover { background: var(--surface-2); border-color: var(--text-3); }
button.danger { background: #d9342b; color: #fff; }
button.danger:hover { background: #bf2b23; }
button.sm { padding: 7px 12px; min-height: 36px; font-size: 13px; }

.row { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.login-wrap { max-width: 380px; margin: 8vh auto; }

/* ---------- file rows ---------- */
/* Phone: name on top, actions on their own full-width line.
   Desktop: one tidy line with the actions revealed on hover. */
.item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 11px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.item:last-child { border-bottom: 0; }
.item .icon { font-size: 21px; width: 26px; text-align: center; flex: none; line-height: 1; }
.item .name {
  flex: 1 1 55%;
  min-width: 0;
  font-size: 14.5px;
  font-weight: 520;
  overflow-wrap: anywhere;
}
.item .name small {
  display: block;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 400;
  margin-top: 2px;
}
.item > button { flex: none; min-height: 38px; }
.item.clickable { cursor: pointer; }
.item.clickable:hover { background: var(--surface-2); }
.item.clickable:active { background: var(--accent-soft); }
.item.busy { opacity: .55; pointer-events: none; }

@media (min-width: 720px) {
  .item { padding: 11px 16px; }
}

/* ---------- folder tiles ---------- */
/* Sections on the home page shouldn't read like a file list, so folders get
   compact tiles and files stay as rows. A folder holding both shows both. */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  padding: 14px;
}
.grid:not(:last-child) { border-bottom: 1px solid var(--border); }

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 16px 14px;
  min-height: 108px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .08s;
}
.tile:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  background: var(--surface);
}
.tile:active { transform: scale(.98); }
.tile-icon { font-size: 26px; line-height: 1; }
.tile-name {
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tile .badge { position: absolute; top: 10px; right: 10px; padding: 3px 7px; }

@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; padding: 16px; }
  .tile { min-height: 120px; }
}

/* ---------- search ---------- */
.searchbar { display: flex; gap: 9px; align-items: center; margin-bottom: 12px; }
.searchbar input { flex: 1; }
.searchbar button { flex: none; min-height: 44px; padding: 0 14px; }
.found {
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

/* ---------- breadcrumbs ---------- */
.crumbs {
  font-size: 13.5px;
  color: var(--text-2);
  margin: 0 2px 12px;
  line-height: 2;
}
.crumbs a {
  color: var(--text-2);
  cursor: pointer;
  text-decoration: none;
  padding: 3px 7px;
  border-radius: 6px;
  transition: background .12s, color .12s;
}
.crumbs a:hover { background: var(--accent-soft); color: var(--accent); }
.crumbs a:last-of-type { color: var(--text); font-weight: 550; }
.crumbs span { color: var(--text-3); padding: 0 1px; }

/* ---------- feedback ---------- */
.msg {
  padding: 11px 13px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  margin-top: 12px;
  display: none;
}
.msg.err { background: var(--err-bg); color: var(--err-fg); display: block; }
.msg.ok  { background: var(--ok-bg);  color: var(--ok-fg);  display: block; }
.empty { padding: 44px 20px; text-align: center; color: var(--text-3); font-size: 14px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--border); }
th {
  color: var(--text-3);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: uppercase;
}
tr:last-child td { border-bottom: 0; }

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.tabs button {
  flex: 1;
  background: transparent;
  color: var(--text-2);
  border: 0;
  padding: 9px 6px;
  min-height: 38px;
  font-size: 13px;
  font-weight: 550;
}
.tabs button:hover { background: var(--surface-2); color: var(--text); }
.tabs button.active { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-sm); }

/* ---------- badges ---------- */
.badge {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
  flex: none;
}
.badge.off  { background: var(--err-bg);  color: var(--err-fg);  border-color: transparent; }
.badge.lock { background: var(--lock-bg); color: var(--lock-fg); border-color: transparent; }
.badge.ok   { background: var(--ok-bg);   color: var(--ok-fg);   border-color: transparent; }

/* ---------- modals ---------- */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(9, 13, 20, .55);
  backdrop-filter: blur(3px);
  z-index: 50;
  padding: 16px;
  overflow-y: auto;
}
.modal-bg.open { display: flex; align-items: center; justify-content: center; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 22px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  animation: rise .18s ease-out;
}
.modal h2 { font-size: 16.5px; font-weight: 640; margin: 0 0 6px; letter-spacing: -.01em; }
@keyframes rise {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

/* ---------- document viewer ---------- */
.viewer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #0d1017;
  flex-direction: column;
}
.viewer.open { display: flex; }
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  height: 54px;
  flex: none;
  background: #171c25;
  border-bottom: 1px solid #262e3a;
  color: #e8ecf3;
}
.viewer-bar .title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.viewer-bar button.ghost {
  background: transparent;
  color: #cbd3e0;
  border-color: #38424f;
}
.viewer-bar button.ghost:hover { background: #222a35; color: #fff; }

.viewer-body {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 10px 28px;
  text-align: center;
}
@media (min-width: 720px) { .viewer-body { padding: 22px; } }

/* Page images: full width on a phone, capped and lifted on a big screen. */
.viewer-body img.page {
  display: block;
  width: 100%;
  max-width: 860px;
  margin: 0 auto 14px;
  background: #fff;
  border-radius: 3px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
  pointer-events: none;          /* no long-press "save image" menu */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.viewer-body img.plain {
  max-width: 100%;
  margin: 0 auto;
  border-radius: var(--r-sm);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
}
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-body.frame { padding: 0; }
.viewer-note { color: #8a94a6; font-size: 14px; padding: 60px 20px; text-align: center; }
