* { box-sizing: border-box; margin: 0; }
:root {
  --bg: #0a0a0b; --bg-elev: #141417; --card: #141417;
  --navy: #ffffff; /* heading color — kept name for minimal diff, now light-on-dark */
  --ink: #ffffff; --text: #f4f4f6; --muted: #9a9aa4; --muted-dim: #6c6c76;
  --border: rgba(255,255,255,.12); --line-strong: rgba(255,255,255,.24);
  --mint: #e50914; --mint-dark: #b20710;
  --blue: #5976f0; --green: #34d399; --red: #ff5c56; --amber: #ffb300;
  --radius: 16px; --radius-sm: 8px;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --glass-bg: linear-gradient(155deg, rgba(255,255,255,.07), rgba(255,255,255,.02));
  --glass-shadow: 0 8px 28px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.08);
}
:root[data-theme="light"] {
  --bg: #f2f3f6; --bg-elev: #ffffff; --card: #ffffff;
  --navy: #14151a;
  --ink: #14151a; --text: #20222b; --muted: #6b6f7b; --muted-dim: #9298a6;
  --border: rgba(10,10,20,.10); --line-strong: rgba(10,10,20,.22);
  --mint: #e50914; --mint-dark: #b20710;
  --blue: #3b5bdb; --green: #15803d; --red: #dc2626; --amber: #b45309;
  --glass-bg: linear-gradient(155deg, rgba(255,255,255,.92), rgba(255,255,255,.72));
  --glass-shadow: 0 8px 28px rgba(15,23,42,.08), inset 0 1px 0 rgba(255,255,255,.6);
}
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased; transition: background .15s ease, color .15s ease; }
.hidden { display: none !important; }

/* Login */
#login-screen {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background:
    radial-gradient(60% 55% at 82% 8%, rgba(89,118,240,.16), transparent 60%),
    radial-gradient(55% 50% at 12% 92%, rgba(229,9,20,.14), transparent 60%),
    var(--bg);
}
.login-card {
  background: var(--glass-bg); backdrop-filter: blur(20px) saturate(160%); -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border); box-shadow: var(--glass-shadow);
  padding: 44px; border-radius: var(--radius); width: 360px; text-align: center;
}
.eyebrow {
  display: inline-flex; align-items: center; gap: 9px; text-transform: uppercase; letter-spacing: 2.5px;
  font-size: 12px; font-weight: 700; color: var(--mint); margin: 0 0 16px;
}
.eyebrow::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 12px var(--mint); }
#login-logo { width: 240px; margin: 0 auto 28px; }
.login-card input { width: 100%; margin-bottom: 12px; }
.login-card .btn { display: inline-block; width: 100%; box-sizing: border-box; text-decoration: none; margin-bottom: 12px; }

/* Layout */
#app { display: flex; min-height: 100vh; }
#sidebar { width: 220px; background: var(--bg-elev); color: #fff; display: flex; flex-direction: column; padding: 24px 0; position: fixed; top: 0; bottom: 0; border-right: 1px solid var(--border); }
#sidebar .brand { padding: 0 22px 24px; }
.brand-logo { display: block; height: auto; }
#sidebar-logo { width: 100%; }
#sidebar a { color: var(--muted); text-decoration: none; padding: 12px 22px; font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; border-left: 3px solid transparent; transition: color .15s ease, background .15s ease, border-color .15s ease; }
#sidebar a:hover { background: rgba(255,255,255,.06); color: var(--ink); }
#sidebar a.active { background: rgba(229,9,20,.12); color: var(--ink); border-left-color: var(--mint); }
#sidebar .spacer { flex: 1; }
#main { flex: 1; margin-left: 220px; padding: 28px 32px; max-width: 1280px; }

/* Elements */
h2.page-title { font-size: 22px; font-weight: 800; letter-spacing: -.01em; color: var(--navy); margin-bottom: 18px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
input, select, textarea {
  padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font-size: 14px;
  font-family: inherit; background: rgba(255,255,255,.04); color: var(--ink);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--mint); outline-offset: -1px; }
textarea { width: 100%; resize: vertical; }
.btn {
  padding: 9px 16px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: rgba(255,255,255,.05);
  cursor: pointer; font-size: 13.5px; font-weight: 700; letter-spacing: .2px; color: var(--ink);
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: rgba(255,255,255,.11); border-color: #fff; transform: translateY(-1px); }
.btn.primary { background: var(--mint); color: #fff; border-color: var(--mint); }
.btn.primary:hover { background: var(--mint-dark); border-color: var(--mint-dark); }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 13px; }

.card {
  background: var(--glass-bg); backdrop-filter: blur(18px) saturate(150%); -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--border); box-shadow: var(--glass-shadow); border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
.card h3 { font-size: 15px; font-weight: 700; letter-spacing: -.01em; color: var(--navy); margin-bottom: 12px; }

/* Stats row */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--glass-bg); backdrop-filter: blur(18px) saturate(150%); -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--border); box-shadow: var(--glass-shadow); border-radius: var(--radius); padding: 16px 20px;
}
.stat .num { font-size: 28px; font-weight: 800; letter-spacing: -.01em; color: var(--ink); }
.stat .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; margin-top: 4px; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--bg-elev); border-radius: var(--radius); overflow: hidden; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.03); }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: rgba(255,255,255,.05); }
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; background: var(--bg-elev); }

/* Badges */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 700; background: rgba(255,255,255,.09); color: var(--text); }
.badge.blue { background: rgba(89,118,240,.18); color: #a9b8ff; }
.badge.green { background: rgba(52,211,153,.16); color: #6be8b3; }
.badge.red { background: rgba(255,92,86,.16); color: #ff9c98; }
.badge.amber { background: rgba(255,179,0,.16); color: #ffd166; }
.badge.navy { background: var(--mint); color: #fff; }

/* Kanban */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.kanban-col { min-width: 230px; width: 230px; background: rgba(255,255,255,.03); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; flex-shrink: 0; }
.kanban-col h4 { font-size: 13px; font-weight: 700; color: var(--ink); padding: 4px 6px 10px; display: flex; justify-content: space-between; }
.kanban-col h4 .sum { color: var(--muted); font-weight: 500; }
.deal-card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 8px; cursor: grab; transition: border-color .15s ease; }
.deal-card:hover { border-color: var(--line-strong); }
.deal-card:active { cursor: grabbing; }
.deal-card .deal-name { font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.deal-card .deal-meta { font-size: 12px; color: var(--muted); line-height: 1.5; }
.deal-card .deal-value { font-weight: 700; color: var(--green); font-size: 13px; margin-top: 4px; }
.kanban-col.drag-over { outline: 2px dashed var(--mint); }

/* Activity feed */
.feed-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.feed-item:last-child { border-bottom: none; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--mint); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.avatar.anon { background: rgba(255,255,255,.16); color: var(--muted); }
.feed-body { flex: 1; min-width: 0; }
.feed-body .who { font-weight: 700; color: var(--ink); }
.feed-body .what { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.feed-time { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* Newsletter editor */
.editor-layout { display: grid; grid-template-columns: 1fr 420px; gap: 20px; align-items: start; }
.block { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: var(--bg-elev); }
.block-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.block-head .type { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.block-head .block-actions button { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 14px; padding: 2px 6px; }
.block input, .block textarea { width: 100%; margin-bottom: 6px; }
.add-block-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.preview-frame { width: 100%; height: 640px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }

/* Modal */
#modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
#modal {
  background: var(--bg-elev); border: 1px solid var(--border); box-shadow: var(--glass-shadow);
  border-radius: var(--radius); padding: 26px; width: 480px; max-width: 100%; max-height: 88vh; overflow: auto; color: var(--text);
}
#modal h3 { color: var(--ink); margin-bottom: 16px; }
#modal label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 4px; }
#modal input, #modal select, #modal textarea { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* Toast */
#toast { position: fixed; bottom: 24px; right: 24px; background: var(--bg-elev); border: 1px solid var(--border); border-left: 3px solid var(--mint); color: var(--ink); padding: 12px 20px; border-radius: var(--radius-sm); z-index: 100; box-shadow: var(--glass-shadow); }
#toast.error { background: var(--mint-dark); border-left-color: var(--red); color: #fff; }
.error { color: var(--red); font-size: 13px; margin-top: 8px; min-height: 18px; }

.detail-grid { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
.kv { margin-bottom: 10px; }
.kv .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.kv .v { font-size: 14px; color: var(--text); }
.back-link { color: var(--muted); text-decoration: none; font-size: 13px; display: inline-block; margin-bottom: 12px; }
.back-link:hover { color: var(--ink); }
.muted { color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button { background: none; border: none; padding: 9px 14px; cursor: pointer; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 700; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--mint); }

@media (max-width: 900px) {
  #sidebar { width: 60px; }
  #sidebar .brand { display: none; }
  #main { margin-left: 60px; padding: 16px; }
  .editor-layout, .detail-grid { grid-template-columns: 1fr; }
}

/* Light theme overrides (non-variable colors) */
[data-theme="light"] #login-screen {
  background:
    radial-gradient(60% 55% at 82% 8%, rgba(89,118,240,.12), transparent 60%),
    radial-gradient(55% 50% at 12% 92%, rgba(229,9,20,.10), transparent 60%),
    var(--bg);
}
[data-theme="light"] #sidebar a.active { background: rgba(229,9,20,.08); }
[data-theme="light"] input, [data-theme="light"] select, [data-theme="light"] textarea { background: #fff; }
[data-theme="light"] .btn:not(.primary) { background: #fff; }
[data-theme="light"] .btn:not(.primary):hover { background: #f2f3f6; border-color: #14151a; }
[data-theme="light"] th { background: rgba(10,10,20,.03); }
[data-theme="light"] tr.clickable:hover { background: rgba(10,10,20,.035); }
[data-theme="light"] .badge { background: rgba(10,10,20,.07); }
[data-theme="light"] .badge.blue { background: rgba(59,91,219,.12); color: #2c46b8; }
[data-theme="light"] .badge.green { background: rgba(21,128,61,.12); color: #15803d; }
[data-theme="light"] .badge.red { background: rgba(220,38,38,.12); color: #b91c1c; }
[data-theme="light"] .badge.amber { background: rgba(180,83,9,.14); color: #92400e; }
[data-theme="light"] .kanban-col { background: rgba(10,10,20,.03); }
[data-theme="light"] .avatar.anon { background: rgba(10,10,20,.12); }
[data-theme="light"] #modal-overlay { background: rgba(15,23,42,.45); }
[data-theme="light"] #toast.error { background: #fde8e7; color: #7a1210; }

/* Theme toggle switch */
.theme-toggle {
  margin: 0 22px 12px; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: rgba(255,255,255,.05); color: var(--muted);
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  cursor: pointer; text-align: center;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--line-strong); }
