/* Resourcecloud customer portal - design tokens and shell.
   Accent #1c7ed6 matches the marketing site's own light-theme blue
   (rescloud-website/html/css/theme-light.css) so the portal reads as the
   same product. Every categorical pair below (accent/alert/wait) was run
   through the dataviz skill's six-check colour validator in both modes. */

:root {
  --bg: #F3F6FA;
  --sidebar-bg: #E7EDF4;
  --card-bg: #FFFFFF;
  --border: #D7E0EA;
  --border-soft: #EDF1F6;
  --text: #12202E;
  --text-muted: #44586C;
  --text-faint: #5C7085;

  --accent: #1C7ED6;
  --accent-bg: #E7F1FB;
  --accent-border: #C5DDF4;

  --alert: #C2255C;
  --alert-bg: #FCEAF0;
  --alert-border: #F2CEDB;

  --wait: #B5730A;
  --wait-bg: #FBF3E3;
  --wait-border: #EBDCBB;

  --muted-bg: #EEF2F7;
  --muted-border: #DCE4ED;

  --radius: 4px;
  --font-display: 'Nunito', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181D;
    --sidebar-bg: #1A1F26;
    --card-bg: #1E242C;
    --border: #2A323C;
    --border-soft: #232A33;
    --text: #E7ECF2;
    --text-muted: #A9B4C0;
    --text-faint: #7E8B99;

    --accent: #4E93DC;
    --accent-bg: rgba(78, 147, 220, 0.16);
    --accent-border: rgba(78, 147, 220, 0.38);

    --alert: #DA5C7B;
    --alert-bg: rgba(218, 92, 123, 0.16);
    --alert-border: rgba(218, 92, 123, 0.38);

    --wait: #C79A2C;
    --wait-bg: rgba(199, 154, 44, 0.16);
    --wait-border: rgba(199, 154, 44, 0.38);

    --muted-bg: #232A33;
    --muted-border: #2E3742;
  }
}

:root[data-theme="dark"] {
  --bg: #14181D;
  --sidebar-bg: #1A1F26;
  --card-bg: #1E242C;
  --border: #2A323C;
  --border-soft: #232A33;
  --text: #E7ECF2;
  --text-muted: #A9B4C0;
  --text-faint: #7E8B99;

  --accent: #4E93DC;
  --accent-bg: rgba(78, 147, 220, 0.16);
  --accent-border: rgba(78, 147, 220, 0.38);

  --alert: #DA5C7B;
  --alert-bg: rgba(218, 92, 123, 0.16);
  --alert-border: rgba(218, 92, 123, 0.38);

  --wait: #C79A2C;
  --wait-bg: rgba(199, 154, 44, 0.16);
  --wait-border: rgba(199, 154, 44, 0.38);

  --muted-bg: #232A33;
  --muted-border: #2E3742;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--text); }

button, input, select, textarea { font: inherit; color: inherit; }
textarea::placeholder, input::placeholder { color: var(--text-faint); }

h1, h2 { font-family: var(--font-display); font-weight: 300; margin: 0; color: var(--text); }
h1 { font-size: 32px; }
h2 { font-size: 15px; font-weight: 600; }

.mono { font-family: var(--font-mono); }

/* ---------- shell ---------- */

.portal-shell { display: flex; min-height: 100vh; }

.portal-nav {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 28px 0 24px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.portal-nav .brand { padding: 0 22px 30px; display: flex; flex-direction: column; gap: 6px; }
.portal-nav .brand .sub { font-size: 12px; font-weight: 500; color: var(--text-faint); margin-top: 1px; }

/* Official Resourcecloud wordmark - same two-file light/dark pair and swap
   pattern the licensing dashboard uses (licensing/src/layout.php).
   align-self: flex-start is load-bearing: both .brand containers are flex
   columns, whose default align-items: stretch otherwise stretches the
   image's WIDTH to fill the column while its height stays fixed - an <img>
   has no aspect-ratio of its own to fall back on against that, so the
   wordmark rendered squashed wide instead of at its real proportions.
   No fixed height here either: the sidebar's own width bounds it to ~176px
   (220px rail minus the .brand padding), well under this logo's ~7:1 aspect
   ratio at any height worth showing, so a fixed height overflowed past the
   sidebar edge into the main content. max-width: 100% + auto height lets it
   fill whatever box it's actually in without ever overflowing either way;
   signin.php's larger, explicitly-sized use (its own promo panel is wide
   enough) sets height inline and relies on this same rule for the width. */
.brand-logo { display: block; height: auto; max-width: 100%; align-self: flex-start; }
.brand-logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-logo-light { display: none; }
  :root:not([data-theme="light"]) .brand-logo-dark { display: block; }
}
:root[data-theme="dark"] .brand-logo-light { display: none; }
:root[data-theme="dark"] .brand-logo-dark { display: block; }

.portal-nav .links { display: flex; flex-direction: column; gap: 2px; padding-left: 14px; }
.portal-nav .links a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  margin-right: 13px;
  font-size: 14px;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: var(--radius);
}
.portal-nav .links a:hover { color: var(--text); }
.portal-nav .links a.active {
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border-color: var(--border);
  border-right-color: var(--bg);
  border-radius: var(--radius) 0 0 var(--radius);
  margin-right: -1px;
}
.portal-nav .links a .count { font-size: 12px; font-weight: 500; color: var(--text-faint); }
.portal-nav .links a.active .count { color: var(--text-faint); }

.portal-nav .account { margin-top: auto; padding: 0 22px; }
.portal-nav .account .rule { height: 1px; background: var(--border); margin-bottom: 16px; }
.portal-nav .account .who { font-size: 13px; font-weight: 500; }
.portal-nav .account .company { font-size: 12px; color: var(--text-faint); margin-top: 1px; }
.portal-nav .account .signout { display: inline-block; font-size: 12px; color: var(--text-faint); margin-top: 10px; }

.portal-main { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; }

.portal-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 22px 48px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}
.portal-header .company { font-size: 14px; font-weight: 500; }
.portal-header .instance { font-family: var(--font-mono); font-size: 13px; }
.portal-header .back { font-size: 14px; color: var(--text-muted); }

.portal-content { padding: 36px 48px 56px; display: flex; flex-direction: column; gap: 28px; max-width: 1180px; }

/* ---------- primitives ---------- */

.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); }
.card-pad { padding: 26px 28px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  background: none;
}
.btn-primary { color: #fff; background: var(--accent); }
.btn-primary:hover { color: #fff; opacity: 0.92; }
.btn-secondary { color: var(--text); background: var(--card-bg); border-color: var(--border); }
.btn-secondary:hover { color: var(--text); background: var(--bg); }
.btn[disabled] { opacity: 0.5; cursor: default; }

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid transparent;
}
.pill-accent { color: var(--accent); background: var(--accent-bg); border-color: var(--accent-border); }
.pill-alert  { color: var(--alert);  background: var(--alert-bg);  border-color: var(--alert-border); }
.pill-wait   { color: var(--wait);   background: var(--wait-bg);   border-color: var(--wait-border); }
.pill-muted  { color: var(--text-faint); background: var(--muted-bg); border-color: var(--muted-border); }

.age-track { position: relative; width: 84px; height: 4px; background: var(--muted-bg); border-radius: 2px; flex-shrink: 0; }
.age-fill { position: absolute; left: 0; top: 0; height: 4px; border-radius: 2px; }

/* Rich-text comment bodies - already sanitized server-side (rc_sanitize_html()
   in htdocs/api/portal/index.php) before this page ever sees them, so they
   render as real HTML, not escaped text. Just sane default spacing for the
   handful of tags the sanitizer allows through. */
.rt p, .rt ul, .rt ol, .rt blockquote, .rt pre { margin: 0 0 0.8em; }
.rt p:last-child, .rt ul:last-child, .rt ol:last-child,
.rt blockquote:last-child, .rt pre:last-child { margin-bottom: 0; }
.rt ul, .rt ol { padding-left: 1.4em; }
.rt blockquote { padding-left: 12px; border-left: 2px solid var(--border); color: var(--text-muted); }
.rt a { color: var(--accent); }
.rt img { max-width: 100%; border-radius: 4px; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 14px; font-weight: 600; }
.field .hint { font-size: 13px; color: var(--text-faint); }
.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  padding: 11px 14px;
  font-size: 15px;
  color: var(--text);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.field textarea { resize: vertical; line-height: 1.5; }

.notice { font-size: 14px; padding: 12px 16px; border-radius: var(--radius); border: 1px solid; }
.notice-error { color: var(--alert); background: var(--alert-bg); border-color: var(--alert-border); }

table.plain { width: 100%; border-collapse: collapse; }
table.plain th { text-align: left; font-size: 13px; font-weight: 600; color: var(--text-muted); padding: 12px 24px; background: var(--bg); }
table.plain th.num, table.plain td.num { text-align: right; }
table.plain td { padding: 14px 24px; font-size: 14px; border-top: 1px solid var(--border-soft); }
table.plain tr:first-child td { border-top: none; }

/* ---------- responsive: bottom tab bar under 768px ---------- */

.portal-tabbar { display: none; }

@media (max-width: 768px) {
  .portal-shell { flex-direction: column; }
  .portal-nav { display: none; }
  .portal-header { padding: 16px 20px; }
  .portal-content { padding: 20px 20px 84px; gap: 20px; }
  h1 { font-size: 26px; }

  .portal-tabbar {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0);
    z-index: 10;
  }
  .portal-tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 56px;
    color: var(--text-faint);
    font-size: 11px;
  }
  .portal-tabbar a svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; }
  .portal-tabbar a.active { color: var(--accent); font-weight: 600; }
}
