/* ==========================================================================
   RCDFlow OS — operations console design system
   App shell (sidebar + topbar), industrial palette, tuned for dense data.
   ========================================================================== */

:root {
  /* Brand */
  --green: #2f8f5b;
  --green-600: #268049;
  --green-050: #e9f4ee;
  --yellow: #e5b634;

  /* Sidebar (dark) */
  --side-bg: #16201d;
  --side-bg-2: #1c2a26;
  --side-text: #b7c6bf;
  --side-text-dim: #7f918a;
  --side-active: #223a30;

  /* Surfaces / neutrals */
  --bg: #f4f6f5;
  --sunken: #eaeeec;
  --surface: #ffffff;
  --line: #e2e7e4;
  --line-2: #d3dad6;
  --text: #16211d;
  --text-2: #5c6b64;
  --muted: #8a978f;

  /* Semantic */
  --ok: #2f8f5b;      --ok-bg: #e7f3ec;   --ok-bd:#bfe0cd;
  --warn: #b07a12;    --warn-bg: #fbf1d8;  --warn-bd:#ecd39c;
  --danger: #c0392b;  --danger-bg: #fbe9e6; --danger-bd:#eec3bc;
  --info: #2f6f8f;    --info-bg: #e6f0f5;  --info-bd:#bad6e2;

  /* Scale */
  --r: 10px; --r-sm: 7px; --r-lg: 16px; --r-pill: 999px;
  --sp-1:4px; --sp-2:8px; --sp-3:12px; --sp-4:16px; --sp-5:24px; --sp-6:32px;
  --side-w: 250px;

  --sh-sm: 0 1px 2px rgba(16,33,29,.06);
  --sh: 0 1px 3px rgba(16,33,29,.08), 0 4px 14px rgba(16,33,29,.05);
  --sh-lg: 0 10px 34px rgba(16,33,29,.14);
  --ring: 0 0 0 3px rgba(47,143,91,.30);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
.ic { width: 20px; height: 20px; flex: none; display: inline-block; vertical-align: middle; }
table, .metric strong, .metric-row strong, .kpi b, .badge { font-variant-numeric: tabular-nums; }

/* ============================================================ App shell === */
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; align-self: start; height: 100vh;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--side-bg-2), var(--side-bg));
  color: var(--side-text); border-right: 1px solid #0f1714;
}
.sidebar__brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px; color: #fff; font-weight: 800; font-size: 17px; letter-spacing: .2px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar__brand b { color: var(--yellow); font-weight: 800; }
.sidebar__nav { flex: 1; overflow-y: auto; padding: 12px 12px 20px; }
.sidebar__group {
  margin: 16px 12px 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--side-text-dim);
}
.sidebar__group:first-child { margin-top: 6px; }
.sidebar__nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; margin: 2px 0; border-radius: var(--r-sm);
  color: var(--side-text); font-weight: 550; font-size: 14px;
  transition: background .14s ease, color .14s ease;
}
.sidebar__nav a .ic { color: var(--side-text-dim); transition: color .14s ease; }
.sidebar__nav a:hover { background: rgba(255,255,255,.05); color: #eef4f1; }
.sidebar__nav a:hover .ic { color: #cdd9d3; }
.sidebar__nav a.active {
  background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--green);
}
.sidebar__nav a.active .ic { color: var(--green); }

.sidebar__user {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.avatar {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; color: #06110c;
  background: linear-gradient(135deg, var(--green), #46b174);
}
.sidebar__user-meta { display: flex; flex-direction: column; min-width: 0; }
.sidebar__user-name { color: #dfe8e3; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user a { color: var(--side-text-dim); font-size: 12px; }
.sidebar__user a:hover { color: var(--green); }

.shell__main { min-width: 0; display: flex; flex-direction: column; }

/* ================================================================ Topbar === */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--sp-3);
  height: 58px; padding: 0 22px;
  background: rgba(255,255,255,.85); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar__toggle { display: none; background: none; border: 0; padding: 6px; border-radius: var(--r-sm); color: var(--text-2); cursor: pointer; }
.topbar__toggle:hover { background: var(--sunken); }
.topbar__brand { display: none; font-weight: 800; }
.topbar__brand b { color: var(--yellow); }
.topbar__spacer { flex: 1; }
.topbar__user { color: var(--text-2); font-size: 13px; }
.langswitch { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r-sm); overflow: hidden; font-size: 12px; font-weight: 700; }
.langswitch a { padding: 5px 9px; color: var(--text-2); background: var(--surface); }
.langswitch a + a { border-left: 1px solid var(--line-2); }
.langswitch a:hover { background: var(--sunken); }
.langswitch a.on { background: var(--green); color: #fff; }

/* ================================================================== Page === */
.page { flex: 1; width: 100%; max-width: 1360px; margin: 0 auto; padding: 26px 28px 48px; }
.page--public { max-width: 1180px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-4); margin-bottom: var(--sp-5); flex-wrap: wrap; }
h1 { font-size: 26px; line-height: 1.2; letter-spacing: -.02em; font-weight: 800; margin: 0 0 var(--sp-4); }
.page-head h1 { margin: 0; }
h2 { font-size: 16px; letter-spacing: -.01em; font-weight: 700; margin: 0 0 var(--sp-3); }
h3 { font-size: 14px; font-weight: 700; margin: 0 0 var(--sp-2); }
p { margin: 0 0 var(--sp-3); }
.muted { color: var(--muted); }

/* ============================================================== Buttons === */
.button, button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 40px; padding: 0 16px; border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 650; font-size: 14px;
  cursor: pointer; box-shadow: var(--sh-sm); transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.button:hover, button:hover { border-color: var(--line-2); box-shadow: var(--sh); }
.button:active, button:active { transform: translateY(1px); }
.button.sm, button.sm { min-height: 32px; padding: 0 12px; font-size: 13px; }
.primary { background: var(--green); border-color: var(--green-600); color: #fff; }
.primary:hover { background: var(--green-600); }
.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.ghost { background: transparent; box-shadow: none; border-color: transparent; }
.ghost:hover { background: var(--sunken); box-shadow: none; }
:where(a,button,input,select,textarea):focus-visible { outline: none; box-shadow: var(--ring); border-color: var(--green); }

/* =============================================================== Cards === */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: var(--sp-4); }
.card, .content-panel, .form-card, .panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; box-shadow: var(--sh-sm);
}
.card:hover { box-shadow: var(--sh); }
.panel { margin-bottom: var(--sp-4); }
.two-col { display: grid; grid-template-columns: 1.5fr .6fr; gap: var(--sp-5); margin-top: var(--sp-2); align-items: start; }

/* ========================================================= KPI / metrics === */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-5); }
.metric, .metric-row div {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 16px 18px; box-shadow: var(--sh-sm); overflow: hidden;
}
.metric::before, .metric-row div::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 3px; background: var(--green); }
.metric span, .metric-row span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 4px; }
.metric strong, .metric-row strong { font-size: 25px; font-weight: 800; letter-spacing: -.02em; }
.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-5); }
.metric-row div { display: block; }

/* =============================================================== Tables === */
.data-table, .panel > table, .two-col table { box-shadow: var(--sh-sm); }
table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.two-col table, .panel table { }
thead th {
  background: var(--sunken); color: #40504a; font-weight: 700; font-size: 11.5px;
  letter-spacing: .05em; text-transform: uppercase; text-align: left; padding: 11px 16px;
  border-bottom: 1px solid var(--line);
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: #f6faf8; }
td a { color: var(--green-600); font-weight: 600; }
td a:hover { text-decoration: underline; }
tr[data-href] { cursor: pointer; }

/* =============================================================== Badges === */
.badge, .pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--r-pill);
  font-size: 11.5px; font-weight: 700; line-height: 1.7; border: 1px solid transparent; white-space: nowrap; letter-spacing: .01em;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-bd); }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-bd); }
.badge.danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-bd); }
.badge.info { background: var(--info-bg); color: var(--info); border-color: var(--info-bd); }
.badge.neutral { background: var(--sunken); color: var(--text-2); border-color: var(--line-2); }

/* =============================================================== Alerts === */
.alert { border: 1px solid var(--danger-bd); border-left: 4px solid var(--danger); background: var(--danger-bg); padding: 12px 14px; border-radius: var(--r-sm); margin-bottom: var(--sp-2); }

/* =============================================================== Kanban === */
.kanban { display: grid; grid-template-columns: repeat(5, minmax(200px, 1fr)); gap: var(--sp-3); align-items: start; }
.kanban-col { background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; min-height: 220px; }
.kanban-col h2, .kanban-col h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); margin-bottom: 10px; }
.job-card {
  display: grid; gap: 3px; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--green);
  border-radius: var(--r-sm); padding: 12px; margin: 8px 0; box-shadow: var(--sh-sm); transition: box-shadow .15s, transform .05s;
}
.job-card:hover { box-shadow: var(--sh); transform: translateY(-1px); }

/* ================================================================ Forms === */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--sp-4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 22px; box-shadow: var(--sh-sm); }
.form-grid label { display: grid; gap: 6px; font-weight: 650; font-size: 13px; }
.form-grid .wide { grid-column: 1 / -1; }
input, select, textarea { width: 100%; min-height: 40px; border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 8px 11px; font: inherit; background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s; }
textarea { min-height: 110px; }
.action-row { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-4); }
.pillar-strip { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin: 0 0 var(--sp-5); }
.pillar-strip span { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--green); border-radius: var(--r-sm); padding: 8px 12px; font-weight: 650; font-size: 12.5px; box-shadow: var(--sh-sm); }
.portal-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 26px; box-shadow: var(--sh-sm); }

/* =============================== Public header + hero (anonymous pages) === */
.pubbar { display: flex; align-items: center; gap: var(--sp-4); height: 62px; padding: 0 26px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
.pubbar .brand, .pubbar__spacer { display: flex; align-items: center; }
.pubbar__spacer { flex: 1; }
.brand { gap: 10px; font-weight: 800; text-decoration: none; color: var(--text); }
.public-hero { display: grid; grid-template-columns: 1.3fr .7fr; gap: var(--sp-6); align-items: center; min-height: 420px; }
.public-hero h1 { font-size: 44px; max-width: 760px; }
.public-hero p { font-size: 18px; color: var(--text-2); max-width: 680px; }
.industrial-panel { background: linear-gradient(180deg, var(--side-bg-2), var(--side-bg)); color: #fff; border-left: 8px solid var(--yellow); padding: 28px; display: grid; gap: var(--sp-3); border-radius: var(--r); box-shadow: var(--sh-lg); }
.industrial-panel strong { font-size: 24px; }
.industrial-panel span { color: #cfdbd5; }

/* ================================================================= Auth === */
.auth-panel { max-width: 420px; margin: 7vh auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 34px; box-shadow: var(--sh-lg); }
.auth-panel h1 { font-size: 22px; }
.messages { display: grid; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.message { padding: 11px 14px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--green); border-radius: var(--r-sm); box-shadow: var(--sh-sm); }
.message.error { border-left-color: var(--danger); background: var(--danger-bg); }

/* ================================================ Mobile off-canvas nav === */
.sidebar__scrim { display: none; }
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(84vw, var(--side-w)); z-index: 60;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--sh-lg);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .sidebar__scrim { display: block; position: fixed; inset: 0; background: rgba(10,18,15,.42); z-index: 50; }
  .topbar__toggle { display: inline-flex; }
  .topbar__brand { display: block; }
}
@media (max-width: 720px) {
  .page { padding: 18px 16px 40px; }
  .kanban { grid-template-columns: 1fr; }
  .two-col, .public-hero { grid-template-columns: 1fr; }
  .public-hero h1 { font-size: 32px; }
  .topbar__user { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
