/* 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;

  /* Railway livery: deep indigo-blue masthead with a maroon rule, rather than a
     generic SaaS purple — this is a divisional office portal, not an app. */
  --brand:         #0f3268;
  --brand-2:       #17457f;
  --brand-rule:    #8c1d2f;
  --on-brand:      #f2f6fc;
  --on-brand-2:    #a9bede;

  --accent:        #1a4fa0;
  --accent-hover:  #16407f;
  --accent-soft:   #eaf0fb;
  --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;

    --brand:         #0b2445;
    --brand-2:       #123256;
    --brand-rule:    #a3283c;
    --on-brand:      #e8eefa;
    --on-brand-2:    #8ba3c8;

    --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;
}

/* ---------- masthead ----------
   An office masthead, not an app bar: crest, the unit's full name, and the
   division it belongs to, over a maroon rule. */
header {
  padding: 11px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  border-bottom: 3px solid var(--brand-rule);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.crest {
  width: 36px;
  height: 36px;
  flex: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .35));
}
.brand-text { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.brand-text .org {
  font-size: 13.5px;
  font-weight: 680;
  line-height: 1.2;
  letter-spacing: -.005em;
  color: var(--on-brand);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand-text .sub {
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--on-brand-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

header .actions { display: flex; align-items: center; gap: 8px; flex: none; }
header a { color: var(--on-brand-2); text-decoration: none; font-size: 13px; }
header a:hover { color: var(--on-brand); }
header .who {
  font-size: 12.5px;
  color: var(--on-brand-2);
  max-width: 26vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Header buttons sit on the dark masthead, so they need their own treatment. */
header button.ghost {
  background: rgba(255, 255, 255, .12);
  color: var(--on-brand);
  border: 1px solid rgba(255, 255, 255, .18);
}
header button.ghost:hover { background: rgba(255, 255, 255, .2); }

main { max-width: 1080px; margin: 0 auto; padding: 16px 14px 32px; }

/* ---------- footer ---------- */
.site-foot {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 14px 34px;
  text-align: center;
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--text-3);
}
.site-foot .rule {
  height: 1px;
  background: var(--border);
  margin: 0 auto 14px;
  max-width: 260px;
}
.site-foot a { color: var(--text-3); text-decoration: none; }
.site-foot a:hover { color: var(--accent); text-decoration: underline; }

@media (min-width: 720px) {
  header { padding: 13px 24px; }
  .crest { width: 42px; height: 42px; }
  .brand-text .org { font-size: 16px; }
  .brand-text .sub { font-size: 11px; }
  header .who { max-width: 220px; font-size: 13px; }
  main { padding: 24px 24px 32px; }
}

/* ---------- 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;
  align-items: center;      /* icon beside the name keeps sections compact */
  gap: 11px;
  padding: 12px 13px;
  min-height: 0;
  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;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, transform .08s;
}
/* A brand-coloured spine marks each tile as a section of the office, and grows
   on hover instead of the whole card jumping. */
.tile::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--brand);
  opacity: .55;
  transition: width .15s, opacity .15s;
}
.tile:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.tile:hover::before { width: 5px; opacity: 1; }
.tile:active { transform: scale(.985); }

.tile-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 9px;
  background: var(--accent-soft);
  font-size: 18px;
  line-height: 1;
}
.tile-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tile .badge { flex: none; padding: 3px 7px; }

@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; padding: 16px; }
}

/* ---------- search ---------- */
.crumbrow { display: flex; align-items: center; gap: 10px; }
.crumbrow .crumbs { flex: 1; min-width: 0; }
.crumbrow button { flex: none; min-height: 36px; padding: 0 12px; font-size: 13px; }

.order-input { width: 62px; flex: none; padding: 8px; text-align: center; font-size: 14px; }

.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;
}
/* An unlocked file is downloadable anyway, so blocking long-press there would
   only get in the way. */
.viewer-body img.page.open {
  pointer-events: auto;
  user-select: auto;
  -webkit-user-select: auto;
  -webkit-touch-callout: default;
}
.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; }
/* Frame mode: the iframe takes the space that's left, so a fallback link below
   it stays visible instead of being pushed off the bottom. */
.viewer-body.frame { padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.viewer-body.frame iframe { flex: 1; height: auto; min-height: 0; }
.viewer-fallback { padding: 10px; text-align: center; }
.viewer-fallback a { color: #cbd5e1; font-size: 13px; text-decoration: underline; }

.viewer-note { color: #8a94a6; font-size: 14px; padding: 60px 20px; text-align: center; }
