/* =========================================================================
   Console 3CX — Trois-Rivières Chevrolet
   Design tokens & composants. Recréation Twig/CSS du prototype hi-fi.
   ========================================================================= */

:root {
  --black: #0E0E10;
  --app-bg: #ECEAE5;
  --surface: #FFFFFF;
  --surface-alt: #FAF9F6;
  --border: #E2DFD8;
  --border-field: #D8D5CE;
  --border-header: #DAD7D0;
  --text: #1A1A1D;
  --text-strong: #25251F;
  --text-2: #6F6E68;
  --text-muted: #8A8882;
  --text-faint: #A09E97;

  --ok-text: #15683C;   --ok-bg: #E6F1EA;   --ok-dot: #1E9E5A;   --ok-term: #6CE3A0;
  --warn-text: #9A6700; --warn-bg: #FBF3DE; --warn-dot: #D9A400;
  --err-text: #B42318;  --err-bg: #FCEEEA;  --err-dot: #E5372A;  --err-border: #F2D2C7;
  --in: #1E9E5A;  --in-bg: #E6F1EA;
  --out: #2563A8; --out-bg: #E7EEF6;

  --radius-card: 12px;
  --radius-field: 8px;
  --radius-modal: 14px;
  --shadow-modal: 0 24px 60px rgba(0,0,0,.3);

  --font-sans: 'Manrope', system-ui, -apple-system, sans-serif;
  --font-display: 'Archivo', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--app-bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
input, button, textarea, select { font-family: inherit; }
input::placeholder, textarea::placeholder { color: #A9A7A0; }
a { color: inherit; }
code { font-family: var(--font-mono); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #C9C6BF; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }

@keyframes trcfade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes trcpulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes trcspin { to { transform: rotate(360deg); } }

.tnum { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }
.fade-in { animation: trcfade .26s ease both; }

/* ============================ LOGIN ===================================== */
.login {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  background: var(--app-bg);
}
.login__hero {
  background: var(--black);
  color: #fff;
  padding: 56px 60px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.login__watermark {
  position: absolute; right: -120px; top: -60px;
  font-family: var(--font-display); font-style: italic; font-weight: 800;
  font-size: 460px; line-height: .8; color: rgba(255,255,255,0.025);
  letter-spacing: -.04em; user-select: none; pointer-events: none;
}
.login__logo { height: 107px; width: 305px; position: relative; object-fit: scale-down; }
.login__mid { position: relative; }
.login__kicker { font-size: 15px; color: #B6B4AE; }
.login__title { font-family: var(--font-display); font-weight: 800; font-size: 46px; line-height: 1.02; letter-spacing: -.02em; margin: 14px 0 0; }
.login__desc { font-size: 15px; line-height: 1.6; color: #B6B4AE; max-width: 380px; margin: 18px 0 0; }
.login__powered { display: flex; align-items: center; gap: 12px; margin: 28px 0 0; }
.login__powered span { font-size: 12px; color: #76746E; letter-spacing: .04em; }
.login__powered img { height: 20px; width: auto; opacity: .9; }
.login__foot { position: relative; display: flex; gap: 28px; font-size: 12.5px; color: #76746E; }
.login__form-wrap { display: flex; align-items: center; justify-content: center; padding: 40px; }
.login__form { width: 100%; max-width: 372px; }
.login__h2 { font-family: var(--font-display); font-weight: 700; font-size: 26px; letter-spacing: -.01em; margin: 0; }
.login__sub { font-size: 14px; color: var(--text-2); margin: 8px 0 30px; }
.login__row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 26px; }
.login__remember { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #56554F; cursor: pointer; }
.login__remember input { width: 15px; height: 15px; accent-color: var(--black); }
.login__forgot { font-size: 13px; color: var(--text); font-weight: 600; text-decoration: none; }
.login__footnote { font-size: 12px; color: #9C9A94; text-align: center; margin: 28px 0 0; }
.login__error {
  background: var(--err-bg); border: 1px solid var(--err-border); color: var(--err-text);
  font-size: 13px; padding: 10px 12px; border-radius: var(--radius-field); margin-bottom: 18px;
}

.field-label { display: block; font-size: 12.5px; font-weight: 600; color: #44433F; margin-bottom: 7px; }
.field {
  width: 100%; height: 46px; padding: 0 14px;
  border: 1px solid var(--border-field); border-radius: var(--radius-field);
  background: #fff; font-size: 14.5px; color: var(--text); outline: none;
}
.field:focus { border-color: #B7B3AA; }
.field--sm { height: 42px; font-size: 14px; padding: 0 13px; border-radius: 7px; }

/* ============================ APP SHELL ================================= */
.shell { min-height: 100vh; display: flex; background: var(--app-bg); }

.sidebar {
  width: 248px; flex: none; background: var(--black); color: #fff;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar__head { padding: 22px 22px 18px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar__head img { height: 26px; width: auto; }
.sidebar__label { font-size: 10.5px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; color: #6E6C66; margin-top: 12px; }
.sidebar__nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; border: none; border-radius: 8px; cursor: pointer;
  font-family: var(--font-sans); font-size: 14px; text-align: left;
  text-decoration: none; font-weight: 500; background: transparent; color: #A7A5A0;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,0.04); }
.nav-item.is-active { background: #fff; color: var(--black); font-weight: 700; }
.nav-item.is-active:hover { background: #fff; }
.sidebar__foot { padding: 14px; border-top: 1px solid rgba(255,255,255,0.08); }
.userbox { display: flex; align-items: center; gap: 11px; padding: 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: #2A2A2E; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex: none;
}
.userbox__name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.userbox__role { font-size: 11.5px; color: #76746E; }
.userbox__logout { background: none; border: none; color: #76746E; cursor: pointer; padding: 4px; display: flex; }
.userbox__logout:hover { color: #fff; }
.sidebar__powered { display: flex; align-items: center; gap: 8px; padding: 10px 8px 4px; }
.sidebar__powered span { font-size: 10.5px; color: #56554F; letter-spacing: .04em; }
.sidebar__powered img { height: 14px; width: auto; opacity: .65; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; overflow-y: auto; }
.topbar {
  height: 60px; flex: none; background: rgba(236,234,229,0.82); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-header); display: flex; align-items: center;
  justify-content: space-between; padding: 0 32px; position: sticky; top: 0; z-index: 10;
}
.topbar__title { font-family: var(--font-display); font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.topbar__right { display: flex; align-items: center; gap: 18px; }
.pbx-badge {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600;
  color: var(--ok-text); background: var(--ok-bg); border: 1px solid #BFE0CC;
  padding: 6px 11px; border-radius: 999px;
}
.pbx-badge--off { color: var(--err-text); background: var(--err-bg); border-color: var(--err-border); }
.pbx-badge__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok-dot); animation: trcpulse 2s ease-in-out infinite; }
.pbx-badge--off .pbx-badge__dot { background: var(--err-dot); }
.topbar__sync { font-size: 12.5px; color: var(--text-2); }
.content { padding: 32px; flex: 1; }
.page { max-width: 1180px; }
.page--narrow { max-width: 760px; }

/* ============================ CARDS ===================================== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
.card--pad { padding: 22px; }
.card--pad-lg { padding: 24px; }
.card-title { font-family: var(--font-display); font-weight: 700; font-size: 16px; margin: 0; }
.card-head { display: flex; align-items: center; gap: 11px; }
.card-head h3 { font-family: var(--font-display); font-weight: 700; font-size: 17px; margin: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 18px 20px; }
.stat__label { font-size: 12px; font-weight: 600; color: #807E78; text-transform: uppercase; letter-spacing: .04em; }
.stat__value { font-family: var(--font-display); font-weight: 800; font-size: 34px; letter-spacing: -.02em; margin: 8px 0 4px; font-variant-numeric: tabular-nums; }
.stat__sub { font-size: 12.5px; color: var(--text-muted); }

.grid-2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* Dashboard widgets */
.activity-row { display: flex; align-items: center; gap: 13px; padding: 11px 0; border-bottom: 1px solid #F0EEE9; }
.activity-row:last-child { border-bottom: none; }
.activity-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.activity-text { font-size: 13.5px; font-weight: 500; color: var(--text-strong); }
.activity-time { font-size: 12px; color: #9A988F; white-space: nowrap; font-variant-numeric: tabular-nums; }
.card--black { background: var(--black); color: #fff; border-radius: var(--radius-card); padding: 22px; }
.card--black .ov-label { font-size: 12px; font-weight: 600; color: #8E8C86; text-transform: uppercase; letter-spacing: .06em; }
.card--black .ov-value { font-family: var(--font-display); font-weight: 800; font-size: 28px; margin: 10px 0 2px; }
.card--black .ov-sub { font-size: 13px; color: #B6B4AE; }
.run-pill { font-size: 11.5px; font-weight: 700; padding: 4px 10px; border-radius: 999px; display: inline-block; }
.run-pill--ok { color: var(--ok-term); background: rgba(108,227,160,0.12); }
.run-pill--warn { color: #F4C95B; background: rgba(217,164,0,0.14); }
.run-pill--error { color: #F39B8E; background: rgba(229,55,42,0.15); }
.alert-box { display: flex; align-items: flex-start; gap: 11px; padding: 10px; background: var(--err-bg); border: 1px solid var(--err-border); border-radius: 9px; }
.alert-box svg { flex: none; margin-top: 1px; }
.alert-box__text { font-size: 13px; color: #8A2B1C; line-height: 1.45; }

/* ============================ BUTTONS =================================== */
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 18px;
  border-radius: var(--radius-field); font-size: 14px; font-weight: 700; cursor: pointer;
  border: none; white-space: nowrap; text-decoration: none;
}
.btn--primary { background: var(--black); color: #fff; }
.btn--primary:hover { background: #26262A; }
.btn--ghost { background: #fff; border: 1px solid var(--border-field); color: #2A2A26; font-weight: 600; }
.btn--ghost:hover { background: var(--surface-alt); }
.btn--sm { height: 40px; font-size: 13.5px; padding: 0 16px; border-radius: 7px; }
.btn--block { width: 100%; justify-content: center; height: 48px; font-size: 15px; }

/* ============================ TABLES ==================================== */
.table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); overflow: hidden; }
.table__row {
  display: grid; gap: 12px; padding: 15px 22px; border-bottom: 1px solid #F1EFEA; align-items: center;
}
.table__row:last-child { border-bottom: none; }
.table__head {
  display: grid; gap: 12px; padding: 13px 22px; background: var(--surface-alt);
  border-bottom: 1px solid #E8E5DE; font-size: 11.5px; font-weight: 700; color: #908E87;
  text-transform: uppercase; letter-spacing: .05em;
}
.table__empty { padding: 48px; text-align: center; color: #9A988F; font-size: 14px; }
.cols-ext { grid-template-columns: 80px 1.6fr 100px 1.1fr 120px 110px; }
.cols-rec { grid-template-columns: 130px 70px 1.2fr 1fr 90px 90px 130px 44px; }
.text-right { text-align: right; }
.ext-num { font-family: var(--font-display); font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }

/* Status pills */
.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 4px 9px; border-radius: 999px;
}
.pill__dot { width: 6px; height: 6px; border-radius: 50%; }
.pill--ok { color: var(--ok-text); background: var(--ok-bg); } .pill--ok .pill__dot { background: var(--ok-dot); }
.pill--warn { color: var(--warn-text); background: var(--warn-bg); } .pill--warn .pill__dot { background: var(--warn-dot); }
.pill--error { color: var(--err-text); background: var(--err-bg); } .pill--error .pill__dot { background: var(--err-dot); }
.pill--idle { color: #6F6E68; background: #EFEDE7; } .pill--idle .pill__dot { background: #A8A7A1; }
.pill--info { color: var(--out); background: var(--out-bg); } .pill--info .pill__dot { background: var(--out); }

/* Direction badge */
.dir { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; align-items: center; justify-content: center; flex: none; }
.dir--in { background: var(--in-bg); } .dir--out { background: var(--out-bg); }
.dir svg { transform: rotate(0deg); }
.dir--in svg { transform: rotate(135deg); }

/* Toggle switch */
.toggle { position: relative; width: 42px; height: 24px; border-radius: 999px; border: none; cursor: pointer; transition: background .2s; background: #CFCCC4; padding: 0; }
.toggle.is-on { background: var(--black); }
.toggle__knob { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.toggle.is-on .toggle__knob { left: 21px; }

.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: #2A2A26; }
.icon-btn:hover { background: var(--surface-alt); }

/* ============================ TOOLBAR =================================== */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.search { position: relative; flex: 1; max-width: 380px; }
.search svg { position: absolute; left: 13px; top: 13px; }
.search input { width: 100%; height: 42px; padding: 0 14px 0 38px; border: 1px solid var(--border-field); border-radius: var(--radius-field); background: #fff; font-size: 14px; outline: none; }
.segment { display: flex; gap: 4px; background: #E4E1DA; padding: 4px; border-radius: 9px; }
.segment a { height: 34px; padding: 0 14px; display: inline-flex; align-items: center; border: none; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none; background: transparent; color: var(--text-2); }
.segment a.is-active { background: #fff; color: var(--black); }
.spacer { flex: 1; }

/* ============================ MODAL ===================================== */
.overlay { position: fixed; inset: 0; background: rgba(14,14,16,0.55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 24px; animation: trcfade .18s ease both; }
.overlay[hidden] { display: none; }
.modal { background: #fff; border-radius: var(--radius-modal); width: 100%; max-width: 460px; padding: 28px; box-shadow: var(--shadow-modal); }
.modal__title { font-family: var(--font-display); font-weight: 700; font-size: 20px; margin: 0 0 4px; }
.modal__desc { font-size: 13.5px; color: var(--text-2); margin: 0 0 22px; }
.modal__actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* ============================ LOGS ====================================== */
.cron-bar { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.cron-expr { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; }
.cron-expr code { font-size: 13px; color: #2A2A26; background: #F2F0EB; padding: 4px 8px; border-radius: 5px; }
.cron-expr span { font-size: 13px; color: var(--text-2); }
.check-inline { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; color: #56554F; cursor: pointer; white-space: nowrap; }
.check-inline input { width: 16px; height: 16px; accent-color: var(--black); cursor: pointer; }
.log-row { border-bottom: 1px solid #F1EFEA; }
.log-row:last-child { border-bottom: none; }
.log-summary {
  width: 100%; display: grid; grid-template-columns: 24px 180px 100px 1fr 130px 28px; gap: 14px;
  align-items: center; padding: 15px 22px; background: none; border: none; cursor: pointer; text-align: left;
}
.log-summary:hover { background: var(--surface-alt); }
.log-status-dot { width: 11px; height: 11px; border-radius: 50%; }
.log-date { font-size: 14px; font-weight: 600; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.log-statlabel { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.log-detail-summary { font-size: 13px; color: var(--text-2); }
.log-dur { font-size: 13px; color: #908E87; text-align: right; font-variant-numeric: tabular-nums; }
.log-chevron { transition: transform .2s; }
.log-row[open] .log-chevron { transform: rotate(180deg); }
.log-row > summary { list-style: none; }
.log-row > summary::-webkit-details-marker { display: none; }
.terminal-wrap { padding: 4px 22px 20px 60px; }
.terminal {
  background: var(--black); border-radius: 9px; padding: 16px 18px;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.85; color: #C9C7C0; overflow-x: auto;
  white-space: pre-wrap; word-break: break-word;
}
.terminal .t-time { color: #76746E; }
.terminal .t-ok { color: var(--ok-term); }
.terminal .t-ok-line { color: var(--ok-term); }
.terminal .t-white { color: #fff; }
.terminal .t-err { color: #F39B8E; }
.terminal > div { white-space: pre-wrap; word-break: break-word; }

/* ============================ SETTINGS ================================== */
.settings { display: flex; flex-direction: column; gap: 18px; }
.form-grid { display: grid; gap: 14px; }
.cols-2-1 { grid-template-columns: 2fr 1fr; }
.cols-1-1 { grid-template-columns: 1fr 1fr; }
.mb-14 { margin-bottom: 14px; }
.mb-18 { margin-bottom: 18px; }
.field-hint { font-size: 13.5px; color: var(--text-2); margin: 0 0 20px; }
.inset-code { font-family: var(--font-mono); font-size: 12px; background: #F2F0EB; padding: 2px 6px; border-radius: 4px; }
.field--mono { font-family: var(--font-mono); color: #2A2A26; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--surface-alt); border: 1px solid #EDEAE3; border-radius: 8px;
}
.setting-row__title { font-size: 13.5px; font-weight: 600; color: var(--text-strong); }
.setting-row__desc { font-size: 12.5px; color: var(--text-muted); }
.terminal-inset { margin-top: 14px; padding: 12px 14px; background: var(--black); border-radius: 8px; font-family: var(--font-mono); font-size: 12.5px; color: #C9C7C0; overflow-x: auto; }
.terminal-inset .t-time { color: #76746E; }
.status-inline { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; }
.status-inline__dot { width: 7px; height: 7px; border-radius: 50%; }
.status-inline--ok { color: var(--ok-text); } .status-inline--ok .status-inline__dot { background: var(--ok-dot); }
.status-inline--err { color: var(--err-text); } .status-inline--err .status-inline__dot { background: var(--err-dot); }
.status-inline--muted { color: var(--text-muted); } .status-inline--muted .status-inline__dot { background: #C0BEB6; }
.settings-actions { display: flex; justify-content: flex-end; gap: 10px; padding-bottom: 8px; }

.flash { padding: 12px 16px; border-radius: var(--radius-field); font-size: 13.5px; font-weight: 600; margin-bottom: 18px; }
.flash--success { background: var(--ok-bg); color: var(--ok-text); border: 1px solid #BFE0CC; }
.flash--error { background: var(--err-bg); color: var(--err-text); border: 1px solid var(--err-border); }

select.field, select.field--sm { background: #fff; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236F6E68' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center; padding-right: 34px; }

@media (max-width: 980px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
