/* =====================================================================
 * TWG CRM — shared stylesheet
 * ===================================================================== */

:root {
  /* color */
  --bg:            #f5f7f7;
  --surface:       #ffffff;
  --surface-2:     #eef2f2;
  --border:        #dfe6e6;
  --border-strong: #c4cfcf;
  --text:          #0b1f1e;
  --text-muted:    #5b6d6c;
  --text-faint:    #94a3a2;

  --sidebar-bg:        #0f2522;
  --sidebar-bg-2:      #0a1c19;
  --sidebar-text:      #c8d4d2;
  --sidebar-text-dim:  #8da09d;
  --sidebar-active-bg: rgba(20,184,166,0.18);
  --sidebar-active-fg: #ffffff;

  --primary:       #0d9488;
  --primary-hover: #0f766e;
  --primary-soft:  #ecfdf5;

  --success:       #10b981;
  --warning:       #f59e0b;
  --danger:        #ef4444;
  --info:          #3b82f6;

  /* badges */
  --b-green-bg: #d1fae5; --b-green-fg: #065f46;
  --b-amber-bg: #fef3c7; --b-amber-fg: #92400e;
  --b-red-bg:   #fee2e2; --b-red-fg:   #991b1b;
  --b-blue-bg:  #dbeafe; --b-blue-fg:  #1e40af;
  --b-grey-bg:  #e5e7eb; --b-grey-fg:  #374151;
  --b-purple-bg:#ede9fe; --b-purple-fg:#5b21b6;

  /* shape */
  --radius:    8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
  --shadow:    0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
  --shadow-lg: 0 10px 25px rgba(15,23,42,.10), 0 4px 10px rgba(15,23,42,.06);

  --sidebar-w: 240px;
  --topbar-h:  64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
               Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

/* =====================================================================
 * Layout shell — sidebar + main
 * ===================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar__brand {
  padding: 22px 20px 18px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: .2px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar__brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #14b8a6, #0d9488);
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 14px;
  letter-spacing: -0.02em;
}
.sidebar__nav { padding: 14px 10px; flex: 1; }
.sidebar__nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-weight: 500;
  margin-bottom: 2px;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.sidebar__nav a:hover { background: rgba(255,255,255,0.05); color: #fff; }
.sidebar__nav a.is-active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-fg);
}
.sidebar__nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar__user {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex; align-items: center; gap: 10px;
}
.sidebar__user img {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
  background: var(--surface-2);
}
.sidebar__user-name { font-size: 13px; color: #fff; font-weight: 600; }
.sidebar__user-email { font-size: 11px; color: var(--sidebar-text-dim); word-break: break-all; }
.sidebar__user button {
  margin-left: auto;
  background: transparent; border: 1px solid rgba(255,255,255,.15); color: #fff;
  border-radius: 6px; padding: 5px 9px; font-size: 11px; cursor: pointer;
}
.sidebar__user button:hover { background: rgba(255,255,255,.08); }

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar__title { font-size: 18px; font-weight: 700; }
.topbar__spacer { flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: 10px; }
.topbar__hamburger {
  display: none; background: transparent; border: 0; cursor: pointer; padding: 6px;
}
.topbar__hamburger svg { width: 22px; height: 22px; color: var(--text); }

.notif-bell {
  position: relative; background: var(--surface-2); border: 1px solid var(--border);
  width: 38px; height: 38px; border-radius: 8px; display: grid; place-items: center; cursor: pointer;
}
.notif-bell svg { width: 18px; height: 18px; color: var(--text-muted); }
.notif-bell .notif-count {
  position: absolute; top: -4px; right: -4px;
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; display: grid; place-items: center;
}
.notif-panel {
  position: absolute; top: calc(var(--topbar-h) - 8px); right: 28px;
  width: 360px; max-height: 480px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: none;
}
.notif-panel.is-open { display: block; }
.notif-panel h4 { margin: 0; padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.notif-panel ul { list-style: none; margin: 0; padding: 0; }
.notif-panel li {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.notif-panel li.unread { background: var(--primary-soft); }
.notif-panel li small { display: block; color: var(--text-muted); font-size: 11px; margin-top: 3px; }
.notif-panel .empty { padding: 28px; text-align: center; color: var(--text-muted); font-size: 13px; }

.content {
  padding: 24px 28px 60px;
  max-width: 1400px;
  width: 100%;
}
.page-header {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-header h1 { margin: 0; font-size: 22px; font-weight: 700; }
.page-header__sub { color: var(--text-muted); font-size: 13px; }
.page-header__actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* =====================================================================
 * Cards / surfaces
 * ===================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card__body { padding: 18px 20px; }
.card__head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.card__head h2 { margin: 0; font-size: 15px; font-weight: 700; }

.stat-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 22px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.stat__label { color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat__value { font-size: 28px; font-weight: 800; margin-top: 4px; }
.stat__icon {
  position: absolute; top: 16px; right: 16px;
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center;
}
.stat__icon svg { width: 18px; height: 18px; }

/* =====================================================================
 * Forms
 * ===================================================================== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, label.field__label {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .03em;
}
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 9px 11px;
  font-size: 14px; font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13,148,136,.20);
}
.textarea { resize: vertical; min-height: 80px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }

/* Combobox / searchable dropdown */
.combo { position: relative; }
.combo__menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 260px; overflow-y: auto;
  z-index: 5;
  display: none;
}
.combo.is-open .combo__menu { display: block; }
.combo__option {
  padding: 9px 11px; font-size: 14px; cursor: pointer;
}
.combo__option:hover, .combo__option.is-active { background: var(--primary-soft); color: var(--primary); }

/* =====================================================================
 * Buttons
 * ===================================================================== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  font-size: 13px; font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--border); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-hover); }
.btn--danger  { background: var(--danger);  color: #fff; }
.btn--danger:hover { background: #b91c1c; }
.btn--ghost   { background: transparent; border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn svg { width: 14px; height: 14px; }

/* =====================================================================
 * Tables
 * ===================================================================== */
.table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.table thead th {
  text-align: left;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:nth-child(even) td { background: rgba(241,243,249,0.4); }
.table tbody tr:hover td { background: var(--primary-soft); }
.table .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }

/* =====================================================================
 * Badges
 * ===================================================================== */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: var(--b-grey-bg); color: var(--b-grey-fg);
  white-space: nowrap;
}
.badge--green  { background: var(--b-green-bg);  color: var(--b-green-fg); }
.badge--amber  { background: var(--b-amber-bg);  color: var(--b-amber-fg); }
.badge--red    { background: var(--b-red-bg);    color: var(--b-red-fg); }
.badge--blue   { background: var(--b-blue-bg);   color: var(--b-blue-fg); }
.badge--purple { background: var(--b-purple-bg); color: var(--b-purple-fg); }
.badge--grey   { background: var(--b-grey-bg);   color: var(--b-grey-fg); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot--online { background: var(--success); }
.dot--offline { background: #cbd5e1; }

/* =====================================================================
 * Modal
 * ===================================================================== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.55);
  display: none;
  align-items: flex-start; justify-content: center;
  padding: 60px 20px 40px;
  z-index: 100;
  overflow-y: auto;
}
.modal-backdrop.is-open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 720px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal--narrow { max-width: 480px; }
.modal__head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}
.modal__head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.modal__close {
  margin-left: auto; background: transparent; border: 0; cursor: pointer; padding: 4px;
  color: var(--text-muted);
}
.modal__body { padding: 20px 22px; max-height: 65vh; overflow-y: auto; }
.modal__foot {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
  background: var(--surface-2);
}

/* =====================================================================
 * Toolbar (filters)
 * ===================================================================== */
.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.toolbar .input, .toolbar .select { width: auto; min-width: 140px; }
.toolbar__search { flex: 1; min-width: 220px; max-width: 360px; }

/* =====================================================================
 * Tabs
 * ===================================================================== */
.tabs {
  display: flex; gap: 2px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.tabs button {
  background: transparent; border: 0;
  padding: 10px 16px;
  font-size: 13px; font-weight: 600;
  color: var(--text-muted); cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs button.is-active {
  color: var(--primary);
  border-color: var(--primary);
}

/* =====================================================================
 * Kanban
 * ===================================================================== */
.kanban {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  padding: 16px;
}
.kanban__col {
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  padding: 12px;
  min-height: 200px;
}
.kanban__col h4 {
  margin: 0 0 10px;
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: space-between;
}
.kanban__col h4 .count {
  background: var(--surface);
  padding: 2px 8px; border-radius: 999px;
  color: var(--text); font-weight: 700;
}
.kanban__card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.kanban__card:hover { border-color: var(--primary); }
.kanban__card-name { font-weight: 600; font-size: 13px; }
.kanban__card-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* =====================================================================
 * Login page
 * ===================================================================== */
.login-page {
  min-height: 100vh;
  display: grid; place-items: center;
  background: radial-gradient(120% 80% at 20% 0%, #134e4a 0%, #0a1c19 55%, #050d0c 100%);
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  padding: 40px 36px;
  width: 100%; max-width: 420px;
  text-align: center;
}
.login-card h1 { font-size: 26px; margin: 16px 0 6px; letter-spacing: -0.01em; }
.login-card p { color: var(--text-muted); margin: 0 0 24px; }
.login-form {
  display: flex; flex-direction: column; gap: 14px;
  text-align: left;
  margin-bottom: 4px;
}
.login-form .field > label {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: 4px;
}
.login-form .input {
  padding: 11px 13px;
  font-size: 14px;
}
.login-submit {
  margin-top: 6px;
  width: 100%;
  justify-content: center;
  padding: 12px 18px;
  font-size: 14px;
}
.login-hint {
  margin-top: 18px !important;
  font-size: 12px;
  color: var(--text-faint) !important;
  line-height: 1.5;
}
.login-hint strong { color: var(--text-muted); }
.login-card .brand-mark {
  width: 64px; height: 64px; border-radius: 16px;
  background: linear-gradient(135deg, #14b8a6, #0d9488);
  display: grid; place-items: center;
  margin: 0 auto;
  color: #fff; font-weight: 800; font-size: 26px;
  letter-spacing: -0.02em;
  box-shadow: 0 8px 24px rgba(13,148,136,.35);
}
.google-btn {
  display: inline-flex; align-items: center; gap: 12px;
  padding: 12px 22px;
  background: #fff; color: #1f2937;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-weight: 600; font-size: 14px;
  cursor: pointer;
  transition: box-shadow .15s, transform .15s;
}
.google-btn:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.google-btn img { width: 18px; height: 18px; }
.login-error {
  margin-top: 14px;
  background: var(--b-red-bg); color: var(--b-red-fg);
  border-radius: var(--radius);
  padding: 10px 14px; font-size: 13px;
  text-align: left;
}

/* =====================================================================
 * Misc
 * ===================================================================== */
.empty-state {
  padding: 48px 24px; text-align: center;
  color: var(--text-muted); font-size: 14px;
}
.toast-host {
  position: fixed; bottom: 22px; right: 22px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--text); color: #fff;
  padding: 10px 16px; border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13px; min-width: 220px;
  animation: toast-in .2s ease-out;
}
.toast--success { background: var(--success); }
.toast--error   { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(0,0,0,.15); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.charts-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
}
.chart-box { padding: 18px 20px; }
.chart-box h3 { margin: 0 0 12px; font-size: 14px; font-weight: 700; }
.chart-box canvas { max-width: 100%; }

.pagination {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
}
.pagination button {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 12px;
}
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination__info { margin-right: auto; }

/* =====================================================================
 * Responsive
 * ===================================================================== */
@media (max-width: 900px) {
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; width: 260px;
    z-index: 80;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .sidebar.is-open { transform: translateX(0); }
  .topbar__hamburger { display: inline-flex; }
  .content { padding: 18px 18px 40px; }
  .stat__value { font-size: 22px; }
  .notif-panel { right: 12px; left: 12px; width: auto; }
}
