/* ─── TOKENS ─────────────────────────────────────────────────── */
:root {
  --green: #22c55e;
  --green-dark: #16a34a;
  --green-light: #4ade80;
  --green-muted: rgba(34,197,94,.12);
  --green-border: rgba(34,197,94,.25);

  /* Light mode */
  --bg: #f8f9fa;
  --bg2: #ffffff;
  --surface: #ffffff;
  --card: #ffffff;
  --card2: #f1f5f9;
  --border: #e2e8f0;
  --border2: #cbd5e1;
  --text: #0f172a;
  --text2: #475569;
  --text3: #64748b;
  --input-bg: #f8fafc;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.10);
  --nav-bg: rgba(255,255,255,.92);
}

[data-theme="dark"] {
  --bg: #090d0f;
  --bg2: #0f1419;
  --surface: #0f1419;
  --card: #141c22;
  --card2: #1a2430;
  --border: #1e2d3d;
  --border2: #243447;
  --text: #e8edf2;
  --text2: #94a3b8;
  --text3: #64748b;
  --input-bg: #0f1419;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.2);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.4);
  --nav-bg: rgba(20,28,34,.95);
}

/* ─── RESET ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; font-size: 16px; }
body {
  font-family: 'Poppins', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .2s, color .2s;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* ─── SVG ICONS ──────────────────────────────────────────────── */
.icon {
  display: inline-block;
  width: 1.25em;
  height: 1.25em;
  stroke-width: 0;
  stroke: currentColor;
  fill: currentColor;
  vertical-align: middle;
}
.icon-stroke {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ─── THEME TOGGLE ───────────────────────────────────────────── */
.theme-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: var(--card2);
  color: var(--text2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .2s;
  flex-shrink: 0;
}
.theme-btn:hover { background: var(--green-muted); color: var(--green); border-color: var(--green-border); }

/* ─── AUTH SCREEN ────────────────────────────────────────────── */
#auth-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
  background: var(--bg);
  position: relative;
}
.auth-wrap { width: 100%; max-width: 420px; }
.auth-logo {
  text-align: center; margin-bottom: 30px;
}
.auth-logo .logo-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 60px; height: 60px;
  background: var(--green);
  border-radius: 16px;
  margin-bottom: 16px;
  box-shadow: 0 4px 14px rgba(34,197,94,.35);
  color: #000;
}
.auth-logo .logo-mark svg { width: 32px; height: 32px; fill: #000; }
.auth-logo h1 { font-size: 1.75rem; font-weight: 700; color: var(--text); letter-spacing: -.02em; line-height: 1.2; }
.auth-logo p { font-size: 1rem; color: var(--text3); margin-top: 4px; }

.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  box-shadow: var(--shadow-lg);
}
.auth-tabs-row {
  display: flex; gap: 6px;
  background: var(--card2);
  border-radius: 12px; padding: 6px;
  margin-bottom: 24px;
}
.tab {
  flex: 1; padding: 10px; border: none; border-radius: 10px;
  background: transparent; color: var(--text2);
  font-size: 1rem; font-weight: 500; cursor: pointer;
  transition: all .2s; font-family: inherit;
}
.tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.auth-card .theme-btn { position: absolute; top: 24px; right: 24px; }

/* ─── FORMS ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block; font-size: 0.9rem; font-weight: 500;
  color: var(--text2); margin-bottom: 8px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34,197,94,.15);
}
.form-group textarea { resize: vertical; min-height: 90px; }
.form-group select option { background: var(--card); color: var(--text); }

/* ─── BUTTONS ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border: none; border-radius: 10px;
  font-size: 1rem; font-weight: 500; cursor: pointer;
  transition: all .2s; font-family: inherit; white-space: nowrap;
}
.btn-primary {
  background: var(--green); color: #000;
  box-shadow: 0 2px 8px rgba(34,197,94,.3);
  font-weight: 600;
}
.btn-primary:hover { background: var(--green-light); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(34,197,94,.4); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost {
  background: var(--card2); color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--green); color: var(--green); background: var(--green-muted); }
.btn-danger { background: rgba(239,68,68,.1); color: #ef4444; border: 1px solid rgba(239,68,68,.2); }
.btn-danger:hover { background: rgba(239,68,68,.2); }
.btn-warn { background: rgba(245,158,11,.1); color: #f59e0b; border: 1px solid rgba(245,158,11,.2); }
.btn-warn:hover { background: rgba(245,158,11,.2); }
.btn-success { background: var(--green-muted); color: var(--green-dark); border: 1px solid var(--green-border); }
.btn-success:hover { background: rgba(34,197,94,.2); }
.btn-sm { padding: 8px 14px; font-size: 0.9rem; border-radius: 8px; }
.btn-xs { padding: 6px 12px; font-size: 0.85rem; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }
.btn svg { width: 1.1em; height: 1.1em; }

/* ─── ERR MSG ────────────────────────────────────────────────── */
.err-msg { color: #ef4444; font-size: 0.85rem; margin-bottom: 12px; display: none; }

/* ─── LAYOUT ─────────────────────────────────────────────────── */
#app { display: none; }

/* Desktop sidebar */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: 260px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 0;
  z-index: 100;
  transition: background .2s, border-color .2s;
}
.sidebar-head {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.sidebar-logo-mark {
  width: 40px; height: 40px; background: var(--green);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(34,197,94,.3);
  color: #000;
}
.sidebar-logo-mark svg { width: 22px; height: 22px; fill: #000; }
.sidebar-head h2 { font-size: 1.2rem; font-weight: 700; letter-spacing: -.01em; color: var(--text); }
.sidebar-head .theme-btn { margin-left: auto; width: 36px; height: 36px; }

.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 10px;
  cursor: pointer; color: var(--text2);
  font-size: 1rem; font-weight: 500;
  transition: all .2s; margin-bottom: 4px;
  border: none; background: transparent; width: 100%; text-align: left;
  font-family: inherit;
}
.nav-item:hover { background: var(--card2); color: var(--text); }
.nav-item.active { background: var(--green-muted); color: var(--green-dark); font-weight: 600; }
[data-theme="dark"] .nav-item.active { color: var(--green-light); }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.sidebar-foot {
  padding: 16px 12px;
  border-top: 1px solid var(--border);
}
.user-chip {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 10px;
  background: var(--card2); margin-bottom: 12px;
}
.user-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--green); display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 600; color: #000; flex-shrink: 0;
}
.user-chip-info { overflow: hidden; }
.user-chip-info strong { display: block; font-size: 0.95rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; margin-bottom: 2px;}

/* ─── MAIN CONTENT ───────────────────────────────────────────── */
.main {
  margin-left: 260px;
  padding: 32px 40px;
  min-height: 100vh;
}
.page { display: none; }
.page.active { display: block; animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.page-header { margin-bottom: 32px; }
.page-title { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; margin-bottom: 4px; }
.page-sub { font-size: 1rem; color: var(--text2); }

/* ─── STATS GRID ─────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 20px; margin-bottom: 32px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px;
  transition: box-shadow .2s, transform .2s;
  display: flex; flex-direction: column;
}
.stat-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.stat-icon { font-size: 1.8rem; margin-bottom: 16px; color: var(--text2); display: flex; align-items: center; }
.stat-icon svg { width: 32px; height: 32px; }
.stat-num { font-size: 2rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; margin-bottom: 4px; color: var(--text); }
.stat-label { font-size: 0.95rem; color: var(--text3); font-weight: 500; }
.stat-card.accent { background: var(--green); border-color: var(--green); }
.stat-card.accent .stat-num, .stat-card.accent .stat-label, .stat-card.accent .stat-icon { color: #000; }

/* ─── BANNERS ────────────────────────────────────────────────── */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 20px; border-radius: 12px; margin-bottom: 24px;
  font-size: 1rem; font-weight: 500;
}
.banner-warn { background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.25); color: #b45309; }
[data-theme="dark"] .banner-warn { color: #fbbf24; }
.banner svg { width: 20px; height: 20px; flex-shrink: 0; margin-right: 8px; vertical-align: middle; }

/* ─── CARDS ──────────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px;
  box-shadow: var(--shadow);
}
.card + .card, .card + .table-card, .table-card + .card { margin-top: 24px; }
.card h3 { font-size: 1.15rem; font-weight: 600; margin-bottom: 20px; }

/* ─── TABLE ──────────────────────────────────────────────────── */
.table-card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.table-header {
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.table-header h3 { font-size: 1.15rem; font-weight: 600; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th {
  padding: 12px 24px; text-align: left;
  font-size: 0.85rem; color: var(--text3); font-weight: 600;
  border-bottom: 1px solid var(--border);
  background: var(--card2); text-transform: uppercase; letter-spacing: .05em;
  white-space: nowrap;
}
td { padding: 16px 24px; font-size: 0.95rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--card2); }
.td-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── BADGES ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-green { background: var(--green-muted); color: var(--green-dark); border: 1px solid var(--green-border); }
[data-theme="dark"] .badge-green { color: var(--green-light); }
.badge-red { background: rgba(239,68,68,.1); color: #ef4444; border: 1px solid rgba(239,68,68,.2); }
.badge-gray { background: var(--card2); color: var(--text3); border: 1px solid var(--border); }
.badge-yellow { background: rgba(245,158,11,.1); color: #f59e0b; border: 1px solid rgba(245,158,11,.2); }

/* ─── MODAL ──────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 300;
  align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 20px; padding: 32px;
  width: 100%; max-width: 500px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(.95) translateY(10px); } to { opacity: 1; transform: none; } }
.modal h3 { font-size: 1.25rem; font-weight: 700; margin-bottom: 24px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

/* ─── TOAST ──────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 84px; right: 20px;
  z-index: 999; display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
@media (min-width: 769px) { #toast { bottom: 24px; right: 24px; } }
.toast-item {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 18px;
  font-size: 0.95rem; font-weight: 500; min-width: 240px; max-width: 320px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .3s cubic-bezier(0.16, 1, 0.3, 1); pointer-events: all;
  display: flex; align-items: center; gap: 10px;
}
.toast-item.success { border-left: 4px solid var(--green); }
.toast-item.error { border-left: 4px solid #ef4444; }
.toast-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.toast-item.success svg { stroke: var(--green); }
.toast-item.error svg { stroke: #ef4444; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ─── LICENSE KEY ────────────────────────────────────────────── */
.lic-key-display {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 1rem; letter-spacing: .08em;
  color: var(--green-dark); background: var(--green-muted);
  border: 1px solid var(--green-border);
  padding: 6px 12px; border-radius: 8px; display: inline-block;
}
[data-theme="dark"] .lic-key-display { color: var(--green-light); }

/* ─── MOBILE BOTTOM NAV ──────────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 70px; z-index: 200;
  background: var(--nav-bg);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding-bottom: env(safe-area-inset-bottom); /* iOS support */
}
.bottom-nav-inner {
  display: flex; height: 70px; align-items: center; justify-content: space-around;
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  cursor: pointer; border: none; background: transparent;
  color: var(--text3); transition: color .2s;
  font-family: inherit; height: 100%;
}
.bottom-nav-item.active { color: var(--green); }
.bottom-nav-item .bn-icon { display: flex; align-items: center; justify-content: center; }
.bottom-nav-item .bn-icon svg { width: 24px; height: 24px; stroke-width: 2; }
.bottom-nav-item .bn-label { font-size: 0.75rem; font-weight: 500; }

/* ─── MOBILE HEADER ────────────────────────────────────────────── */
.mobile-header {
  display: none;
  align-items: center; justify-content: space-between;
  padding: 16px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 150;
}
.user-chip-mobile {
  display: flex; align-items: center; gap: 12px;
}
.user-chip-mobile .user-avatar {
  width: 34px; height: 34px; font-size: 1rem;
}
.user-chip-info strong {
  font-size: 0.95rem; font-weight: 600;
}

/* ─── RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .bottom-nav { display: block; }
  .mobile-header { display: flex; }
  .main { margin-left: 0; padding: 24px 20px 94px; }
  .page-title { font-size: 1.5rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 16px; }
  .stat-card { padding: 18px; }
  .stat-num { font-size: 1.6rem; }
  .stat-icon svg { width: 28px; height: 28px; }
  .auth-card { padding: 28px 24px; border-radius: 16px; }
  .card { padding: 20px; border-radius: 16px; }
  .table-card { border-radius: 16px; }
  .table-card .table-wrap { -webkit-overflow-scrolling: touch; }
  .modal { border-radius: 20px 20px 0 0; padding: 24px; max-height: 85vh; margin: auto 0 0 0; width: 100%; max-width: none; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .banner { flex-direction: column; align-items: flex-start; gap: 12px; }
  .btn-block-mobile { width: 100%; justify-content: center; }
  table { min-width: 500px; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar { width: 240px; }
  .main { margin-left: 240px; padding: 28px; }
}

/* ─── GRID HELPERS ───────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2-3 { display: grid; grid-template-columns: 1fr 2fr; gap: 24px; }
@media (max-width: 768px) { .grid-2, .grid-2-3 { grid-template-columns: 1fr; } }

/* ─── DIVIDER ────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* ─── EMPTY STATE ────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text3); }
.empty-state .empty-icon { margin-bottom: 16px; display: flex; justify-content: center; color: var(--text3); }
.empty-state .empty-icon svg { width: 48px; height: 48px; opacity: 0.5; }
.empty-state p { font-size: 1rem; font-weight: 500; }

/* ─── KANBAN BOARD ───────────────────────────────────────────── */
.kanban-board {
  display: flex; gap: 24px; overflow-x: auto; padding-bottom: 12px;
}
.kanban-col {
  flex: 1; min-width: 320px;
  background: var(--card2); border: 1px solid var(--border);
  border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 16px;
}
.kanban-col-header {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.kanban-col-body {
  display: flex; flex-direction: column; gap: 12px; min-height: 200px;
}
.kanban-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px;
  box-shadow: var(--shadow); transition: transform 0.2s, box-shadow 0.2s;
}
.kanban-card:hover {
  transform: translateY(-2px); box-shadow: var(--shadow-lg);
}
.kanban-card-header {
  display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px;
}
.kanban-card-title {
  font-weight: 600; font-size: 1.05rem; display: flex; align-items: center; gap: 6px;
}
.kanban-card-meta {
  display: flex; align-items: center; gap: 12px; font-size: 0.85rem; color: var(--text3); margin-bottom: 12px;
}
.kanban-card-actions {
  display: flex; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px;
}

/* ─── TOM SELECT OVERRIDES ───────────────────────────────────── */
.ts-control, .ts-wrapper.single.input-active .ts-control {
  background: var(--input-bg); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); padding: 12px 16px; font-family: inherit; font-size: 1rem;
}
.ts-control.focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.15); }
.ts-dropdown {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); box-shadow: var(--shadow-lg); font-family: inherit; margin-top: 4px;
}
.ts-dropdown .active { background: var(--card2); color: var(--text); }
.ts-dropdown .option { padding: 10px 16px; cursor: pointer; }
.ts-dropdown .option:hover { background: var(--green-muted); color: var(--green-dark); }
[data-theme="dark"] .ts-dropdown .option:hover { color: var(--green-light); }
.ts-wrapper.single .ts-control:after { border-color: var(--text2) transparent transparent transparent; right: 16px; }
.ts-wrapper.single .ts-control.dropdown-active:after { border-color: transparent transparent var(--text2) transparent; }
