/* AvenIQ CRM — application styles. No framework, no build step. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --border-strong: #cbd2d9;
  --text: #1a1d21;
  --text-muted: #6b7280;
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-soft: #eef2ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #0891b2;
  --info-soft: #ecfeff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
  --shadow-lg: 0 10px 24px rgba(16,24,40,.12), 0 2px 6px rgba(16,24,40,.08);
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.sm { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
strong { font-weight: 600; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #0891b2 100%);
}
.login-card {
  width: 100%; max-width: 390px; background: var(--surface);
  border-radius: 16px; padding: 32px; box-shadow: var(--shadow-lg);
}
.login-card h1 { margin: 14px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 20px; }
.login-card label { display: block; margin-bottom: 14px; font-weight: 500; font-size: 13px; }
.login-card input { margin-top: 6px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), #7c3aed); color: #fff;
  font-weight: 700; font-size: 22px;
}
.brand-mark.sm { width: 32px; height: 32px; border-radius: 9px; font-size: 16px; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100%; }

.sidebar {
  background: #111827; color: #cbd5e1; display: flex; flex-direction: column;
  overflow-y: auto;
}
.sidebar-head {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-name { color: #fff; font-weight: 700; font-size: 15px; line-height: 1.1; }
.brand-sub { color: #64748b; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }

#nav { flex: 1; padding: 10px 8px; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 11px;
  color: #cbd5e1; text-decoration: none; border-radius: 7px;
  font-size: 13.5px; margin-bottom: 1px;
}
#nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
#nav a.active { background: var(--brand); color: #fff; font-weight: 500; }
#nav .ico { width: 17px; text-align: center; opacity: .85; font-size: 13px; }
.nav-group {
  padding: 14px 11px 5px; font-size: 10px; letter-spacing: .1em;
  text-transform: uppercase; color: #64748b; font-weight: 600;
}
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { margin-bottom: 9px; font-size: 12.5px; }
.user-chip .name { color: #fff; font-weight: 600; }
.user-chip .role { color: #94a3b8; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }

.main { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 19px; }
.topbar p { margin: 1px 0 0; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.content { flex: 1; overflow-y: auto; padding: 22px 24px 60px; }

/* ---------- forms & buttons ---------- */
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand);
}
textarea { resize: vertical; min-height: 84px; }
label.fld { display: block; margin-bottom: 12px; font-size: 12.5px; font-weight: 500; color: #374151; }
label.fld > span { display: block; margin-bottom: 5px; }
label.fld .req { color: var(--danger); }
label.fld input, label.fld select, label.fld textarea { margin-top: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--border-strong); }
.btn.ghost:hover { background: rgba(255,255,255,.08); }
.sidebar .btn.ghost { color: #cbd5e1; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn {
  background: none; border: none; font-size: 22px; line-height: 1;
  cursor: pointer; color: var(--text-muted); padding: 2px 8px; border-radius: 5px;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* ---------- cards & grid ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0; font-size: 14.5px; font-weight: 600; }
.card-body { padding: 16px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); }

/* KPI tiles */
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 16px; box-shadow: var(--shadow);
}
.kpi .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-muted); font-weight: 600; margin-bottom: 7px;
}
.kpi .value { font-size: 23px; font-weight: 700; line-height: 1.15; letter-spacing: -.02em; }
.kpi .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.kpi.accent { border-left: 3px solid var(--brand); }
.kpi.good   { border-left: 3px solid var(--success); }
.kpi.warn   { border-left: 3px solid var(--warning); }
.kpi.bad    { border-left: 3px solid var(--danger); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; padding: 9px 12px; background: #f9fafb;
  border-bottom: 1px solid var(--border); font-weight: 600;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); white-space: nowrap;
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--brand); }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:hover { background: #fafbfc; }
table.data tbody tr.clickable { cursor: pointer; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .row-actions { display: flex; gap: 5px; justify-content: flex-end; }
.empty { padding: 40px 20px; text-align: center; color: var(--text-muted); }
.empty .big { font-size: 30px; margin-bottom: 8px; opacity: .4; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: #f3f4f6; color: #4b5563;
}
.badge.green  { background: var(--success-soft); color: #047857; }
.badge.red    { background: var(--danger-soft);  color: #b91c1c; }
.badge.amber  { background: var(--warning-soft); color: #b45309; }
.badge.blue   { background: var(--brand-soft);   color: var(--brand-dark); }
.badge.cyan   { background: var(--info-soft);    color: #0e7490; }
.badge.gray   { background: #f3f4f6; color: #4b5563; }

/* ---------- toolbar / filters ---------- */
.toolbar {
  display: flex; gap: 9px; flex-wrap: wrap; align-items: center;
  margin-bottom: 14px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.toolbar input[type=search], .toolbar input[type=text] { flex: 1; min-width: 190px; width: auto; }
.toolbar select { width: auto; min-width: 128px; }
.toolbar .spacer { flex: 1; }

.pager {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px;
}
.pager .pages { display: flex; gap: 6px; align-items: center; }

/* ---------- kanban ---------- */
.kanban { display: flex; gap: 13px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.kcol {
  flex: 0 0 264px; background: #eef0f3; border-radius: var(--radius);
  padding: 10px; min-height: 130px;
}
.kcol-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 9px; padding: 0 3px;
}
.kcol-head .name { font-weight: 600; font-size: 13px; }
.kcol-head .sum { font-size: 11.5px; color: var(--text-muted); }
.kcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 11px; margin-bottom: 7px; box-shadow: var(--shadow); cursor: pointer;
}
.kcard:hover { border-color: var(--brand); }
.kcard .t { font-weight: 600; font-size: 13px; margin-bottom: 3px; }
.kcard .c { font-size: 12px; color: var(--text-muted); }
.kcard .a { font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kcard select { margin-top: 7px; font-size: 12px; padding: 3px 6px; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(17,24,39,.5);
  display: grid; place-items: center; padding: 20px; z-index: 100;
}
.modal {
  background: var(--surface); border-radius: 13px; width: 100%;
  max-width: 660px; max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal.wide { max-width: 940px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  display: flex; gap: 9px; justify-content: flex-end;
  padding: 14px 20px; border-top: 1px solid var(--border);
}

/* ---------- misc ---------- */
.alert { padding: 10px 13px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 13px; }
.alert.error   { background: var(--danger-soft);  color: #991b1b; border: 1px solid #fecaca; }
.alert.success { background: var(--success-soft); color: #065f46; border: 1px solid #a7f3d0; }
.alert.info    { background: var(--brand-soft);   color: var(--brand-dark); border: 1px solid #c7d2fe; }

.toast {
  position: fixed; bottom: 22px; right: 22px; z-index: 200;
  background: #111827; color: #fff; padding: 11px 17px; border-radius: 9px;
  box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 400px;
}
.toast.error { background: var(--danger); }

.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button {
  background: none; border: none; padding: 9px 14px; cursor: pointer;
  font: inherit; font-weight: 500; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

.dl { display: grid; grid-template-columns: 128px 1fr; gap: 7px 14px; font-size: 13.5px; }
.dl dt { color: var(--text-muted); font-weight: 500; }
.dl dd { margin: 0; }

.bar { height: 7px; background: #e5e7eb; border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); }

.timeline { position: relative; padding-left: 22px; }
.timeline::before {
  content: ''; position: absolute; left: 5px; top: 5px; bottom: 5px;
  width: 2px; background: var(--border);
}
.tl-item { position: relative; padding-bottom: 15px; font-size: 13px; }
.tl-item::before {
  content: ''; position: absolute; left: -21px; top: 5px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--brand); border: 2px solid var(--surface);
}
.tl-item .when { font-size: 11.5px; color: var(--text-muted); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 640px) { .two-col { grid-template-columns: 1fr; } }

.line-items { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 12px; }
.line-items th {
  text-align: left; padding: 6px 7px; background: #f9fafb;
  border-bottom: 1px solid var(--border); font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted);
}
.line-items td { padding: 4px 5px; border-bottom: 1px solid var(--border); }
.line-items input, .line-items select { padding: 5px 7px; font-size: 13px; }
.line-items .num { text-align: right; }
.totals { margin-left: auto; width: 260px; font-size: 13.5px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand {
  border-top: 2px solid var(--text); margin-top: 5px; padding-top: 7px;
  font-weight: 700; font-size: 15px;
}

.kanban-note, .hint { font-size: 12.5px; color: var(--text-muted); margin-top: 5px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 90; width: var(--sidebar-w); transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .content { padding: 16px; }
}

/* ---------- demo accounts (click-to-fill) ---------- */
.demo-creds { margin-top: 20px; font-size: 12.5px; }
.demo-creds summary { cursor: pointer; color: var(--text-muted); padding: 4px 0; }
.demo-creds summary:hover { color: var(--brand); }

.demo-list {
  margin-top: 10px;
  display: flex; flex-direction: column; gap: 4px;
}

/* Each account is a real button so it is keyboard- and screen-reader-reachable. */
.demo-row {
  display: grid;
  grid-template-columns: 78px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.demo-row:hover { border-color: var(--brand); background: var(--brand-soft); }
.demo-row:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

.demo-role {
  font-weight: 600; font-size: 11.5px;
  color: var(--brand-dark);
  white-space: nowrap;
}
.demo-email {
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.demo-fill {
  font-size: 11px; font-weight: 600; color: var(--brand);
  white-space: nowrap;
}
/* Confirmation state after a row is clicked. */
.demo-row.filled { border-color: var(--success); background: var(--success-soft); }
.demo-row.filled .demo-fill { color: var(--success); }

.demo-hint {
  margin: 10px 0 0; font-size: 11.5px; line-height: 1.5;
  color: var(--text-muted);
}
