/* =====================================================================
   OCTA Portal UI v9 — theme tokens + components (dark & light)
   ---------------------------------------------------------------------
   Theme is chosen by  <html data-theme="dark|light">  (set by js/octa-theme.js).
   With no data-theme attribute the page follows the system setting.
   Everything visual goes through the CSS variables below, so a component
   written once works in both themes. Do NOT hard-code colours in new CSS:
   use var(--...) tokens.
   ===================================================================== */

@font-face { font-family: "Outfit"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/Outfit-Regular.woff2") format("woff2"); }
@font-face { font-family: "Outfit"; font-weight: 500 700; font-style: normal; font-display: swap; src: url("../fonts/Outfit-SemiBold.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/JetBrainsMono-Regular.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 500; font-style: normal; font-display: swap; src: url("../fonts/JetBrainsMono-Medium.woff2") format("woff2"); }

/* ---------- DARK (default) ---------- */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0B0A10;            /* page background */
  --surface: #15141C;       /* cards, top bar */
  --surface-2: #0E0D13;     /* inset fields (search, password output) */
  --raised: #1E1C27;        /* small tiles, toggles, kbd */
  --line: #201E29;          /* table row dividers */
  --line-strong: #2B2935;   /* card / control borders */
  --text: #EEECF5;
  --muted: #A6A3B8;
  --faint: #8D8AA0;
  --primary-bg: #F2F0F7;    /* main buttons, active tab */
  --primary-fg: #0B0A10;
  --accent: var(--c2);      /* theme colour: selection, focus, checkboxes */
  --accent-soft: color-mix(in srgb, var(--c2) 8%, #15141C);   /* selected card background */
  --row-sel: color-mix(in srgb, var(--c2) 13%, #15141C);       /* selected table row */
  --danger: #FF8A8A;
  --ok: #2EE6A6;
  --ok-fg: #6EF0C2;
  --ok-soft: rgba(46, 230, 166, .14);
  --meter-empty: #23212D;
  --card-shadow: none;
  --feature-bg: #1B1824;    /* password card */
  --feature-line: color-mix(in srgb, var(--c2) 18%, #2B2935);
  --feature-inset: #0B0A10;
  --avatar-ring: #15141C;
  /* file-type tints: background / foreground */
  --t-pink-bg: rgba(240, 50, 143, .16);   --t-pink-fg: #FF8CC3;
  --t-violet-bg: rgba(184, 75, 255, .17); --t-violet-fg: #D2A6FF;
  --t-cyan-bg: rgba(0, 194, 255, .14);    --t-cyan-fg: #7FDFFF;
  --t-orange-bg: rgba(255, 122, 61, .15); --t-orange-fg: #FFB48A;
  --t-gray-bg: #1E1C27;                   --t-gray-fg: #A6A3B8;
  /* storage meter segments */
  --m-video: #F0328F; --m-photos: #B84BFF; --m-docs: #00C2FF; --m-audio: #FF8A4B; --m-other: #5B5870;
}

/* ---------- LIGHT ---------- */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F1F0F5;
  --surface: #FFFFFF;
  --surface-2: #F1F0F5;
  --raised: #F1F0F5;
  --line: #F0EFF4;
  --line-strong: #E3E1EA;
  --text: #16141C;
  --muted: #6B6880;
  --faint: #8A8799;
  --primary-bg: #16141C;
  --primary-fg: #FFFFFF;
  --accent: var(--c2);
  --accent-soft: #FFFFFF;
  --row-sel: color-mix(in srgb, var(--c2) 6%, #fff);
  --danger: #D92D20;
  --ok: #12B886;
  --ok-fg: #0E8A5F;
  --ok-soft: #E2F8EF;
  --meter-empty: #EEEDF3;
  --card-shadow: 0 1px 0 rgba(22, 20, 28, .04), 0 14px 40px rgba(22, 20, 28, .05);
  --feature-bg: #16141C;    /* password card stays dark in light mode */
  --feature-line: #16141C;
  --feature-inset: #0D0C12;
  --avatar-ring: #FFFFFF;
  --t-pink-bg: #FDE7F2;   --t-pink-fg: #D81B7A;
  --t-violet-bg: #F2E6FF; --t-violet-fg: #7A22BD;
  --t-cyan-bg: #E0F6FD;   --t-cyan-fg: #00769C;
  --t-orange-bg: #FFEDE3; --t-orange-fg: #C24A12;
  --t-gray-bg: #F1F0F5;   --t-gray-fg: #6B6880;
  --m-video: #F0328F; --m-photos: #B84BFF; --m-docs: #00B2EB; --m-audio: #FF7A3D; --m-other: #B9B6C6;
}

/* No saved choice: follow the operating system. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #F1F0F5; --surface: #FFFFFF; --surface-2: #F1F0F5; --raised: #F1F0F5; --line: #F0EFF4; --line-strong: #E3E1EA;
    --text: #16141C; --muted: #6B6880; --faint: #8A8799; --primary-bg: #16141C; --primary-fg: #FFFFFF;
    --accent-soft: #FFFFFF; --row-sel: color-mix(in srgb, var(--c2) 6%, #fff); --danger: #D92D20; --ok: #12B886; --ok-fg: #0E8A5F; --ok-soft: #E2F8EF;
    --meter-empty: #EEEDF3; --card-shadow: 0 1px 0 rgba(22, 20, 28, .04), 0 14px 40px rgba(22, 20, 28, .05);
    --feature-bg: #16141C; --feature-line: #16141C; --feature-inset: #0D0C12; --avatar-ring: #FFFFFF;
    --t-pink-bg: #FDE7F2; --t-pink-fg: #D81B7A; --t-violet-bg: #F2E6FF; --t-violet-fg: #7A22BD;
    --t-cyan-bg: #E0F6FD; --t-cyan-fg: #00769C; --t-orange-bg: #FFEDE3; --t-orange-fg: #C24A12;
    --t-gray-bg: #F1F0F5; --t-gray-fg: #6B6880;
    --m-docs: #00B2EB; --m-audio: #FF7A3D; --m-other: #B9B6C6;
  }
}

/* ---------- shared, theme-independent ---------- */
:root {
  /* colour theme (js/octa-theme-boot.js sets the chosen one; these are Pink + Classic) */
  --c1: #ff4b4b; --c2: #f0328f; --c3: #c63bff; --c4: #8f6bff; --c-ink: #ff8cc3;
  --bg-page: #131219;
  --patch1: rgba(240, 50, 143, .22); --patch2: rgba(198, 59, 255, .2); --patch3: rgba(0, 194, 255, .13); --patch4: rgba(126, 91, 255, .14);
  --brand: linear-gradient(110deg, var(--c1), var(--c2) 45%, var(--c3));
  --brand-avatar: linear-gradient(135deg, var(--c1), var(--c2) 45%, var(--c3));
  --radius-xl: 26px;   /* cards */
  --radius-lg: 22px;   /* top bar */
  --radius-md: 14px;   /* buttons, inputs, icon tiles */
  --radius-sm: 12px;
  --font: "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.o-app {
  margin: 0; min-height: 100vh;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}
/* :where() keeps these at zero specificity so component colours (.o-btn-primary etc.) always win */
:where(.o-app) a { color: inherit; text-decoration: none; }
:where(.o-app) button { font: inherit; color: inherit; cursor: pointer; }
.o-app :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.o-mono { font-family: var(--mono); }
.o-icon { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- layout ---------- */
.o-wrap { max-width: 1400px; margin: 0 auto; padding: 22px 32px 44px; }
.o-cols { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 22px; margin-top: 30px; }
.o-main { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.o-aside { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
@media (max-width: 1100px) { .o-cols { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) { .o-wrap { padding: 12px 14px 32px; } }

/* ---------- top bar ---------- */
.o-bar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 10px 10px 22px; border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--card-shadow);
}
:root[data-theme="light"] .o-bar { border-color: transparent; }
.o-bar-logo img { height: 22px; width: auto; display: block; }
.o-tabs { display: flex; gap: 2px; margin-left: 18px; flex-wrap: wrap; }
.o-tabs a { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: var(--radius-sm); color: var(--muted); font-weight: 500; font-size: 14.5px; }
.o-tabs a:hover { color: var(--text); background: var(--raised); }
.o-tabs a[aria-current="page"], .o-tabs a.is-active { background: var(--primary-bg); color: var(--primary-fg); }
.o-tabs a svg { display: none; } /* icons are only used on phone */
.o-search {
  flex: 1; max-width: 460px; margin-left: auto; position: relative;
  display: flex; align-items: center; gap: 10px; height: 46px; padding: 0 12px 0 16px;
  border-radius: var(--radius-md); background: var(--surface-2); border: 1px solid var(--line-strong); color: var(--faint);
}
:root[data-theme="light"] .o-search { border-color: transparent; }
.o-search input { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; color: var(--text); font: inherit; font-size: 14.5px; }
.o-search input::placeholder { color: var(--faint); }
.o-kbd { font-family: var(--mono); font-size: 11px; color: var(--muted); background: var(--raised); border-radius: 7px; padding: 3px 7px; }
.o-avatar {
  width: 46px; height: 46px; border-radius: var(--radius-md); flex: none; overflow: hidden;
  display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--brand-avatar); text-transform: uppercase;
}
.o-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* theme toggle */
.o-theme-toggle {
  width: 46px; height: 46px; border-radius: var(--radius-md); flex: none; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line-strong); color: var(--muted);
}
:root[data-theme="light"] .o-theme-toggle { border-color: transparent; }
.o-theme-toggle:hover { color: var(--text); }
.o-theme-toggle .sun { display: none; }
:root[data-theme="light"] .o-theme-toggle .sun { display: block; }
:root[data-theme="light"] .o-theme-toggle .moon { display: none; }
@media (prefers-color-scheme: light) { :root:not([data-theme]) .o-theme-toggle .sun { display: block; } :root:not([data-theme]) .o-theme-toggle .moon { display: none; } }

/* ---------- headings ---------- */
.o-eyebrow { font-size: 12px; letter-spacing: .09em; font-weight: 600; color: var(--faint); text-transform: uppercase; }
.o-h1 { margin: 0; font-size: 56px; letter-spacing: -.035em; line-height: 1; font-weight: 700; }
.o-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.o-head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
@media (max-width: 640px) { .o-h1 { font-size: 40px; } }

/* ---------- buttons ---------- */
.o-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 46px; padding: 0 18px;
  border-radius: var(--radius-md); font-weight: 600; font-size: 14.5px; border: 0; white-space: nowrap;
}
.o-btn-primary { background: var(--primary-bg); color: var(--primary-fg); }
.o-btn-ghost { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }
.o-btn-ghost:hover { background: var(--raised); }
.o-btn-brand { background: var(--brand); color: #16141C; }
.o-btn-danger { background: var(--surface); color: var(--danger); box-shadow: inset 0 0 0 1px var(--line-strong); }
.o-btn-sm { height: 38px; padding: 0 14px; font-size: 13.5px; border-radius: var(--radius-sm); }
.o-btn-icon { width: 46px; padding: 0; }
.o-btn:disabled { opacity: .5; cursor: default; }

/* ---------- cards ---------- */
.o-card { background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-xl); box-shadow: var(--card-shadow); }
:root[data-theme="light"] .o-card { border-color: transparent; }
@media (prefers-color-scheme: light) { :root:not([data-theme]) .o-card, :root:not([data-theme]) .o-bar { border-color: transparent; } }
.o-card-pad { padding: 20px 24px; }

/* storage meter */
.o-storage { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.o-storage-num { white-space: nowrap; }
.o-storage-num b { font-size: 30px; font-weight: 700; letter-spacing: -.02em; }
.o-storage-num span { color: var(--faint); }
.o-meter { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 10px; }
.o-meter-bar { display: flex; gap: 4px; height: 12px; }
.o-meter-bar i { display: block; border-radius: 3px; }
.o-meter-bar i:first-child { border-radius: 99px 3px 3px 99px; }
.o-meter-bar i:last-child { border-radius: 3px 99px 99px 3px; background: var(--meter-empty); }
.o-meter-legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.o-meter-legend b { color: var(--text); font-weight: 500; }
.o-meter-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 9px; margin-right: 6px; vertical-align: 1px; }
.o-meter-legend .free { margin-left: auto; color: var(--text); font-weight: 500; }

/* folder / space cards */
.o-folders { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 900px) { .o-folders { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.o-folder { padding: 18px; display: flex; flex-direction: column; gap: 22px; text-align: left; }
.o-folder b { font-size: 17px; font-weight: 600; }
.o-folder small { color: var(--faint); font-size: 13px; }
.o-folder.is-active, .o-folder[aria-current] { box-shadow: inset 0 0 0 2px var(--accent); background: var(--accent-soft); }
:root[data-theme="light"] .o-folder.is-active { box-shadow: inset 0 0 0 2px var(--text); }
.o-folder-top { display: flex; justify-content: space-between; align-items: center; }

/* icon tile + file-type chip */
.o-tile { width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center; flex: none; }
.o-ext { width: 40px; height: 40px; border-radius: var(--radius-sm); display: grid; place-items: center; flex: none; font-family: var(--mono); font-size: 10px; font-weight: 500; text-transform: uppercase; }
.t-pink { background: var(--t-pink-bg); color: var(--t-pink-fg); }
.t-violet { background: var(--t-violet-bg); color: var(--t-violet-fg); }
.t-cyan { background: var(--t-cyan-bg); color: var(--t-cyan-fg); }
.t-orange { background: var(--t-orange-bg); color: var(--t-orange-fg); }
.t-gray { background: var(--t-gray-bg); color: var(--t-gray-fg); }

/* chips (filters) */
.o-chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.o-chip { display: inline-flex; align-items: center; height: 34px; padding: 0 14px; border-radius: 99px; font-size: 13.5px; font-weight: 500; color: var(--muted); background: transparent; border: 0; box-shadow: inset 0 0 0 1px var(--line-strong); }
:root[data-theme="light"] .o-chip { background: var(--surface); }
.o-chip[aria-pressed="true"], .o-chip.is-active,
:root[data-theme="light"] .o-chip[aria-pressed="true"], :root[data-theme="light"] .o-chip.is-active { background: var(--primary-bg); color: var(--primary-fg); box-shadow: none; }

/* segmented (list / grid view, password modes) */
.o-seg { display: inline-flex; gap: 2px; padding: 4px; border-radius: var(--radius-sm); background: var(--raised); }
.o-seg button { height: 34px; min-width: 34px; padding: 0 10px; border: 0; border-radius: 9px; background: transparent; color: var(--faint); display: grid; place-items: center; font-size: 12.5px; }
.o-seg button[aria-pressed="true"], .o-seg button.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
:where(:root:not([data-theme="light"])) .o-seg button[aria-pressed="true"] { background: var(--line-strong); }

/* file table */
.o-files { padding: 10px 14px 14px; }
.o-files-head { display: flex; align-items: center; gap: 8px; padding: 10px 6px 4px; flex-wrap: wrap; }
.o-files-head .o-crumb { font-size: 18px; font-weight: 600; margin-right: 10px; }
.o-crumb .sep { color: var(--faint); opacity: .6; }
.o-table-wrap { overflow-x: auto; }
.o-table { width: 100%; border-collapse: collapse; min-width: 560px; }
.o-table th { font-size: 12px; letter-spacing: .07em; color: var(--faint); font-weight: 500; text-align: left; padding: 14px 12px; text-transform: uppercase; }
.o-table td { padding: 11px 12px; border-top: 1px solid var(--line); font-size: 14px; }
.o-table td.dim { color: var(--muted); }
.o-table tr:hover td { background: color-mix(in srgb, var(--raised) 50%, transparent); }
.o-table tr.is-selected td { background: var(--row-sel); }
.o-table tr.is-selected td:first-child { border-radius: 14px 0 0 14px; }
.o-table tr.is-selected td:last-child { border-radius: 0 14px 14px 0; }
.o-name { display: flex; align-items: center; gap: 12px; min-width: 0; }
.o-name b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.o-check { appearance: none; -webkit-appearance: none; width: 20px; height: 20px; margin: 0; border-radius: 6px; border: 1.6px solid color-mix(in srgb, var(--faint) 60%, transparent); display: grid; place-items: center; cursor: pointer; }
.o-check:checked { background: var(--accent); border-color: var(--accent); }
.o-check:checked::after { content: ""; width: 10px; height: 5px; border: solid #fff; border-width: 0 0 2.5px 2.5px; transform: translateY(-1px) rotate(-45deg); }

/* avatar stack */
.o-dots { display: flex; }
.o-dots i { width: 26px; height: 26px; border-radius: 99px; border: 2px solid var(--avatar-ring); font-style: normal; color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.o-dots i + i { margin-left: -8px; }

/* preview panel */
.o-preview { padding: 18px; }
.o-preview-media { height: 170px; border-radius: 18px; background: #16141C; display: flex; align-items: center; justify-content: center; gap: 3px; padding: 0 22px; position: relative; overflow: hidden; }
:root:not([data-theme="light"]) .o-preview-media { background: var(--bg); border: 1px solid var(--line); }
.o-preview-media img, .o-preview-media video { width: 100%; height: 100%; object-fit: contain; }
.o-preview h3 { margin: 16px 4px 0; font-size: 19px; font-weight: 600; word-break: break-word; }
.o-preview .meta { margin: 0 4px; color: var(--faint); font-size: 13.5px; }
.o-preview-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
.o-kv { display: grid; grid-template-columns: 110px 1fr; gap: 10px; font-size: 14px; margin: 0; }
.o-kv dt { color: var(--faint); }
.o-kv dd { margin: 0; }

/* password feature card (dark in both themes) */
.o-feature { border-radius: var(--radius-xl); background: var(--feature-bg); border: 1px solid var(--feature-line); color: #F2F0F7; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.o-feature .o-seg { background: var(--feature-inset); }
.o-feature .o-seg button { color: #A6A3B8; }
.o-feature .o-seg button[aria-pressed="true"] { background: #F2F0F7; color: #16141C; }
.o-pw { font-family: var(--mono); font-size: 19px; line-height: 1.4; word-break: break-all; padding: 14px; border-radius: 14px; background: var(--feature-inset); border: 1px solid #2B2935; color: #F2F0F7; }
.o-pw .d { color: #7FDFFF; }   /* digits */
.o-pw .s { color: var(--c-ink); }   /* symbols */
.o-strength { display: flex; gap: 4px; }
.o-strength i { flex: 1; height: 5px; border-radius: 9px; background: #2B2935; }
.o-strength i.on { background: #2EE6A6; }

/* app list */
.o-apps { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.o-app-row { display: flex; align-items: center; gap: 12px; }
.o-app-row .o-tile { width: 40px; height: 40px; border-radius: 12px; }
.o-app-row small { color: var(--faint); }
.o-badge { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; }
.o-badge-ok { color: var(--ok-fg); background: var(--ok-soft); }
.o-badge-dev { color: var(--t-violet-fg); background: var(--t-violet-bg); }
.o-badge-plan { color: var(--muted); background: var(--raised); }

/* forms (account, users, storage pages) */
.o-field { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; color: var(--muted); }
.o-input, .o-field input, .o-field select {
  height: 46px; padding: 0 14px; border-radius: var(--radius-md); font: inherit; font-size: 14.5px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line-strong); outline: 0;
}
.o-input:focus, .o-field input:focus, .o-field select:focus { border-color: var(--accent); }
.o-note { font-size: 13.5px; color: var(--muted); }
.o-note.ok { color: var(--ok-fg); }
.o-note.err { color: var(--danger); }

/* status dot */
.o-dot { width: 8px; height: 8px; border-radius: 9px; background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); display: inline-block; }

/* ---------- phone ---------- */
@media (max-width: 820px) {
  .o-bar { padding: 10px; gap: 10px; }
  .o-search { order: 5; max-width: none; flex-basis: 100%; margin-left: 0; }
  .o-tabs { order: 6; margin-left: 0; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .o-bar-spacer { flex: 1; }
}
