/* C3 Inbox Copilot — C3PO design standards (navy/blue, Inter, 4px grid) */

:root {
  --brand-primary: #1B2559;
  --brand-accent: #3B82F6;
  --brand-accent-hover: #2563EB;
  --brand-accent-light: #EFF6FF;
  --n-50: #FAFAFA; --n-100: #F5F5F5; --n-200: #E5E5E5; --n-300: #D4D4D4;
  --n-400: #A3A3A3; --n-500: #737373; --n-700: #404040; --n-900: #171717;
  --success: #16A34A; --success-bg: #F0FDF4;
  --warning: #D97706; --warning-bg: #FFFBEB;
  --danger: #DC2626; --danger-bg: #FEF2F2;
  --info: #2563EB; --info-bg: #EFF6FF;
  --neutral-status: #6B7280; --neutral-status-bg: #F3F4F6;
  --radius-sm: 4px; --radius-md: 8px; --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--n-50);
  color: var(--n-900);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-accent); text-decoration: none; }
a:hover { color: var(--brand-accent-hover); }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.rail {
  width: 216px; flex-shrink: 0; background: #fff;
  border-right: 1px solid var(--n-200);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.rail-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 16px 16px;
}
.rail-brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; letter-spacing: .02em;
}
.rail-brand .name { font-weight: 600; font-size: 14px; color: var(--brand-primary); }
.rail-brand .sub { font-size: 11px; color: var(--n-500); margin-top: -2px; }
.rail nav { padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.rail nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-md);
  color: var(--n-700); font-weight: 500; font-size: 13.5px;
}
.rail nav a:hover { background: var(--n-100); }
.rail nav a.active { background: var(--brand-accent-light); color: var(--brand-accent-hover); }
.rail nav a .ico { width: 18px; text-align: center; }
.rail-foot { margin-top: auto; padding: 16px; border-top: 1px solid var(--n-200); }
.rail-foot .who { font-size: 12.5px; font-weight: 600; }
.rail-foot .org { font-size: 11.5px; color: var(--n-500); }
.rail-foot a { font-size: 12px; }

.main { flex: 1; min-width: 0; padding: 28px 36px 64px; max-width: 1180px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { font-size: 26px; font-weight: 700; color: var(--brand-primary); margin: 0 0 2px; letter-spacing: -0.01em; }
.page-head .sub { color: var(--n-500); font-size: 13.5px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font); font-size: 13.5px; font-weight: 600;
  padding: 9px 16px; border-radius: 6px; border: 1px solid transparent;
  cursor: pointer; transition: all .12s ease; white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: 2px; }
.btn-primary { background: var(--brand-accent); color: #fff; }
.btn-primary:hover { background: var(--brand-accent-hover); }
.btn-secondary { background: #fff; color: var(--n-700); border-color: var(--n-200); }
.btn-secondary:hover { border-color: var(--n-300); background: var(--n-50); }
.btn-danger { background: #fff; color: var(--danger); border-color: #FECACA; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-ghost { background: transparent; color: var(--brand-accent); }
.btn-lg { font-size: 14.5px; padding: 12px 22px; }
.btn-sm { font-size: 12.5px; padding: 6px 12px; }
.btn[disabled] { background: var(--n-200); color: var(--n-400); border-color: transparent; cursor: not-allowed; }
.btn .spin { display: none; }
.btn.loading .spin { display: inline-block; }
.btn.loading .label { opacity: .7; }

/* ---------- badges / pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; border-radius: 99px;
  padding: 2.5px 9px; letter-spacing: .01em;
}
.badge-high { color: var(--danger); background: var(--danger-bg); }
.badge-normal { color: var(--warning); background: var(--warning-bg); }
.badge-low { color: var(--neutral-status); background: var(--neutral-status-bg); }
.badge-info { color: var(--info); background: var(--info-bg); }
.badge-success { color: var(--success); background: var(--success-bg); }
.badge-cat { color: var(--n-500); background: var(--n-100); font-weight: 500; }

/* ---------- cards ---------- */
.card {
  background: #fff; border: 1px solid var(--n-200);
  border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
}
.section-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--n-500);
  margin: 26px 0 10px;
}
.section-title .dot { width: 8px; height: 8px; border-radius: 99px; }
.dot-high { background: var(--danger); }
.dot-normal { background: var(--warning); }
.dot-low { background: var(--n-400); }

.mail-card {
  display: block; padding: 14px 18px; cursor: pointer;
  border-bottom: 1px solid var(--n-100); color: inherit;
  transition: background .1s ease;
}
.mail-card:last-child { border-bottom: 0; }
.mail-card:hover, .mail-card.focused { background: var(--brand-accent-light); }
.mail-card .row1 { display: flex; align-items: center; gap: 10px; }
.mail-card .sender { font-weight: 600; font-size: 13.5px; flex-shrink: 0; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-card .subject { font-weight: 500; color: var(--n-700); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.mail-card .when { color: var(--n-400); font-size: 12px; flex-shrink: 0; }
.mail-card .row2 { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.mail-card .rationale { color: var(--n-500); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-card .draft-chip { color: var(--brand-accent-hover); background: var(--brand-accent-light); font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; flex-shrink: 0; }

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field .lbl { display: block; font-size: 12.5px; font-weight: 600; color: var(--n-700); margin-bottom: 5px; }
label.field .hint { font-size: 11.5px; color: var(--n-500); font-weight: 400; }
input[type=text], input[type=email], input[type=password], select, textarea {
  width: 100%; font-family: var(--font); font-size: 13.5px; color: var(--n-900);
  background: #fff; border: 1px solid var(--n-200); border-radius: 6px;
  padding: 9px 12px; transition: border .12s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-accent); box-shadow: 0 0 0 3px rgba(59,130,246,.13); }
textarea { resize: vertical; min-height: 120px; line-height: 1.6; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.note { font-size: 12.5px; color: var(--n-500); }
.alert { padding: 10px 14px; border-radius: var(--radius-md); font-size: 13px; margin: 10px 0; }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #FECACA; }
.alert-ok { background: var(--success-bg); color: var(--success); border: 1px solid #BBF7D0; }
.alert-info { background: var(--info-bg); color: var(--info); border: 1px solid #BFDBFE; }

/* ---------- spinner ---------- */
.spin {
  width: 14px; height: 14px; border-radius: 99px;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
.spin.dark { border-color: var(--n-200); border-top-color: var(--brand-accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(23,23,23,.4);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: min(520px, 92vw); padding: 24px; max-height: 86vh; overflow: auto;
}
.modal h3 { margin: 0 0 6px; font-size: 17px; color: var(--brand-primary); }
.modal .note { margin-bottom: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px; }
.chip {
  font-size: 12.5px; font-weight: 500; padding: 7px 12px;
  border: 1px solid var(--n-200); border-radius: 99px; cursor: pointer;
  background: #fff; color: var(--n-700); transition: all .1s ease;
  font-family: var(--font);
}
.chip:hover { border-color: var(--brand-accent); }
.chip.on { background: var(--brand-accent-light); border-color: var(--brand-accent); color: var(--brand-accent-hover); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- onboarding ---------- */
.onboard-wrap { max-width: 600px; margin: 6vh auto; padding: 0 20px 60px; }
.onboard-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.onboard-logo .logo { width: 40px; height: 40px; border-radius: 10px; background: var(--brand-primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.steps { display: flex; gap: 6px; margin-bottom: 24px; }
.steps .step-dot { height: 4px; flex: 1; border-radius: 99px; background: var(--n-200); transition: background .2s; }
.steps .step-dot.done { background: var(--brand-accent); }
.onboard-card { background: #fff; border: 1px solid var(--n-200); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 30px; }
.onboard-card h2 { margin: 0 0 6px; font-size: 21px; color: var(--brand-primary); letter-spacing: -0.01em; }
.onboard-card .lead { color: var(--n-500); font-size: 13.5px; margin: 0 0 22px; }
.why-safe { margin: 16px 0; border: 1px solid var(--n-200); border-radius: var(--radius-md); background: var(--n-50); }
.why-safe summary { cursor: pointer; padding: 11px 14px; font-size: 12.5px; font-weight: 600; color: var(--n-700); list-style: none; display: flex; align-items: center; gap: 8px; }
.why-safe summary::before { content: "🔒"; }
.why-safe .body { padding: 0 14px 12px; font-size: 12.5px; color: var(--n-500); }
.why-safe .body li { margin-bottom: 4px; }
.onboard-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 22px; }
.quick-start { border: 1px solid #BFDBFE; background: var(--info-bg); border-radius: var(--radius-md); padding: 14px 16px; margin-bottom: 20px; }
.quick-start b { color: var(--brand-primary); }
.provider-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.provider-tile { border: 1px solid var(--n-200); border-radius: var(--radius-md); padding: 13px 14px; cursor: pointer; background: #fff; transition: all .1s; }
.provider-tile:hover { border-color: var(--n-300); }
.provider-tile.on { border-color: var(--brand-accent); background: var(--brand-accent-light); box-shadow: 0 0 0 1px var(--brand-accent); }
.provider-tile .t { font-weight: 600; font-size: 13px; }
.provider-tile .d { font-size: 11.5px; color: var(--n-500); margin-top: 2px; }
.provider-tile.soon { opacity: .55; cursor: not-allowed; }

/* ---------- thread page ---------- */
.thread-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 1000px) { .thread-grid { grid-template-columns: 1fr; } }
.msg { padding: 14px 18px; border-bottom: 1px solid var(--n-100); }
.msg:last-child { border-bottom: 0; }
.msg .from { font-weight: 600; font-size: 13px; }
.msg .date { color: var(--n-400); font-size: 11.5px; margin-left: 8px; }
.msg .body { margin-top: 8px; white-space: pre-wrap; color: var(--n-700); font-size: 13.5px; }
.draft-panel { position: sticky; top: 24px; }
.draft-panel .head { padding: 14px 18px; border-bottom: 1px solid var(--n-200); display: flex; align-items: center; justify-content: space-between; }
.draft-panel .head .t { font-weight: 600; color: var(--brand-primary); display: flex; gap: 8px; align-items: center; }
.draft-panel .inner { padding: 16px 18px; }
.confirm-flag { background: var(--warning-bg); color: var(--warning); border: 1px solid #FDE68A; padding: 8px 12px; border-radius: 6px; font-size: 12.5px; margin-bottom: 12px; }
.draft-actions { display: flex; gap: 10px; margin-top: 14px; align-items: center; }

/* ---------- chat ---------- */
.chat-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 900px) { .chat-layout { grid-template-columns: 1fr; } }
.chat-list a { display: block; padding: 8px 10px; border-radius: 6px; font-size: 12.5px; color: var(--n-700); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list a:hover { background: var(--n-100); }
.chat-list a.active { background: var(--brand-accent-light); color: var(--brand-accent-hover); }
.chat-main { display: flex; flex-direction: column; min-height: 68vh; }
.chat-scroll { flex: 1; display: flex; flex-direction: column; gap: 14px; padding-bottom: 18px; }
.bubble { max-width: 78%; padding: 11px 15px; border-radius: 14px; font-size: 13.5px; white-space: pre-wrap; }
.bubble.user { align-self: flex-end; background: var(--brand-primary); color: #fff; border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: #fff; border: 1px solid var(--n-200); border-bottom-left-radius: 4px; }
.trace { align-self: flex-start; font-size: 11.5px; color: var(--n-400); }
.draft-card { align-self: stretch; background: #fff; border: 1px solid var(--n-200); border-left: 3px solid var(--brand-accent); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); padding: 16px 18px; }
.draft-card .dc-head { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--brand-accent-hover); margin-bottom: 10px; }
.draft-card .sent-stamp { color: var(--success); font-weight: 600; font-size: 12.5px; }
.composer { display: flex; gap: 10px; margin-top: 10px; position: sticky; bottom: 18px; }
.composer textarea { min-height: 52px; max-height: 160px; box-shadow: var(--shadow-md); }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(330px, 100%), 1fr)); gap: 20px; align-items: start; }
.settings-card { padding: 20px 22px; }
.settings-card h3 { margin: 0 0 4px; font-size: 15px; color: var(--brand-primary); }
.settings-card .sub { font-size: 12.5px; color: var(--n-500); margin-bottom: 14px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--n-100); font-size: 13px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--n-500); }
.kv .v { font-weight: 500; text-align: right; overflow: hidden; text-overflow: ellipsis; }
.metric-row { display: flex; gap: 14px; margin: 6px 0 14px; }
.metric { flex: 1; background: var(--n-50); border: 1px solid var(--n-200); border-radius: var(--radius-md); padding: 12px 14px; }
.metric .v { font-size: 22px; font-weight: 700; color: var(--brand-primary); font-variant-numeric: tabular-nums; }
.metric .l { font-size: 11px; color: var(--n-500); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.fb-item { padding: 10px 0; border-bottom: 1px solid var(--n-100); font-size: 12.5px; }
.fb-item:last-child { border-bottom: 0; }
.fb-item .meta { color: var(--n-400); font-size: 11.5px; }

/* ---------- run banner ---------- */
.run-banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius-md); margin-bottom: 18px; font-size: 13px; }
.run-banner.running { background: var(--info-bg); border: 1px solid #BFDBFE; color: var(--info); }
.run-banner.error { background: var(--danger-bg); border: 1px solid #FECACA; color: var(--danger); }
.run-banner.done { background: var(--success-bg); border: 1px solid #BBF7D0; color: var(--success); }

.empty {
  text-align: center; padding: 56px 30px; color: var(--n-500);
}
.empty .big { font-size: 38px; margin-bottom: 10px; }
.empty h3 { color: var(--n-700); margin: 0 0 6px; }

.kbd { font-family: ui-monospace, monospace; font-size: 11px; background: var(--n-100); border: 1px solid var(--n-200); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; color: var(--n-500); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--n-900); color: #fff; font-size: 13px; padding: 10px 18px;
  border-radius: 8px; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none;
  transition: all .2s ease; z-index: 80;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- mobile (≤700px): rail becomes a bottom bar ---------- */
@media (max-width: 700px) {
  .shell { display: block; }
  .rail {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; z-index: 40;
    width: 100%; height: auto; flex-direction: row; align-items: center;
    border-right: 0; border-top: 1px solid var(--n-200);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 10px rgba(0,0,0,.05);
  }
  .rail-brand, .rail-foot { display: none; }
  .rail nav { flex-direction: row; flex: 1; justify-content: space-around; padding: 5px 8px; gap: 4px; }
  .rail nav a { flex-direction: column; gap: 2px; padding: 6px 10px; font-size: 10.5px; min-width: 56px; align-items: center; }
  .rail nav a .ico { width: auto; font-size: 17px; }
  .main { padding: 18px 16px calc(88px + env(safe-area-inset-bottom)); max-width: none; }
  .page-head { flex-wrap: wrap; }
  .page-head h1 { font-size: 22px; }
  .draft-panel { position: static; }
  .mail-card { padding: 12px 14px; }
  .mail-card .sender { max-width: 38vw; }
  .mail-card .row1, .mail-card .row2 { flex-wrap: wrap; row-gap: 4px; }
  .mail-card .subject { flex-basis: 100%; order: 5; }
  .metric-row { flex-wrap: wrap; }
  .metric-row .metric { flex: 1 1 40%; }
  .draft-actions { flex-wrap: wrap; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; }
  .chat-list { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
  .chat-list a { flex-shrink: 0; max-width: 180px; }
  .composer { bottom: calc(74px + env(safe-area-inset-bottom)); }
  /* 16px inputs keep iOS Safari from zooming on focus */
  input[type=text], input[type=email], input[type=password], input[type=number], select, textarea { font-size: 16px; }
}
