/* Symniq CRM — design system
   A dark-sidebar, flat/utilitarian console look — deliberately distinct from
   the reference project's white-card/purple-gradient Bootstrap style. */

:root {
  --ink-950: #0b0f14;
  --ink-900: #10151c;
  --ink-800: #171e28;
  --ink-700: #212a37;
  --ink-600: #2c3646;
  --ink-500: #4a5568;
  --ink-400: #6b7686;
  --ink-300: #94a0b0;
  --ink-200: #c3cad4;
  --ink-100: #e6e9ed;
  --paper: #f5f6f8;
  --card: #ffffff;
  --line: #e2e5ea;

  --accent: #1f6f5c;
  --accent-dark: #175646;
  --accent-soft: #e5f2ee;
  --accent-ink: #0e3d33;

  --amber: #b6752b;
  --amber-soft: #faf1e3;
  --red: #b93a3a;
  --red-soft: #fbeaea;
  --blue: #2a5da8;
  --blue-soft: #e9f0fb;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-1: 0 1px 2px rgba(16, 21, 28, 0.06);
  --shadow-2: 0 4px 16px rgba(16, 21, 28, 0.08);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink-800);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.app-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--ink-950);
  color: var(--ink-200);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
}

.sidebar-brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-brand-text {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  letter-spacing: -0.01em;
}

.sidebar-brand-sub {
  font-size: 11px;
  color: var(--ink-400);
  margin-top: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 12px;
  overflow-y: auto;
}

.sidebar-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-500);
  padding: 14px 10px 6px;
  font-weight: 600;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-300);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: background 0.12s ease, color 0.12s ease;
}

.sidebar-link .ic {
  width: 17px;
  text-align: center;
  font-size: 14px;
  color: var(--ink-400);
}

.sidebar-link:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
}

.sidebar-link.active {
  background: rgba(31, 111, 92, 0.35);
  color: #fff;
}

.sidebar-link.active .ic { color: #7fd8bd; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ink-700);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 12.5px;
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 11px;
  color: var(--ink-500);
}

.sidebar-logout {
  margin-left: auto;
  color: var(--ink-400);
  font-size: 13px;
  padding: 4px;
}
.sidebar-logout:hover { color: #fff; }

/* ---------- Main area ---------- */
.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.topbar-title { font-size: 17px; font-weight: 700; color: var(--ink-900); letter-spacing: -0.01em; }
.topbar-subtitle { font-size: 12.5px; color: var(--ink-400); margin-top: 2px; }

.app-content {
  padding: 24px 28px 48px;
  flex: 1;
}

/* ---------- Flash messages ---------- */
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }

.flash {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
}

.flash-success { background: var(--accent-soft); color: var(--accent-ink); border-color: #c3e3d9; }
.flash-error { background: var(--red-soft); color: #7a2727; border-color: #f0c9c9; }
.flash-info { background: var(--blue-soft); color: #1d3f70; border-color: #c4d7f0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.12s ease;
  line-height: 1.2;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-solid {
  background: var(--accent);
  color: #fff;
}
.btn-solid:hover:not(:disabled) { background: var(--accent-dark); }

.btn-outline {
  background: var(--card);
  color: var(--ink-700);
  border-color: var(--line);
}
.btn-outline:hover:not(:disabled) { background: var(--paper); border-color: var(--ink-300); }

.btn-ghost {
  background: transparent;
  color: var(--ink-500);
}
.btn-ghost:hover:not(:disabled) { background: var(--paper); color: var(--ink-800); }

.btn-danger-outline {
  background: var(--card);
  color: var(--red);
  border-color: #ecc9c9;
}
.btn-danger-outline:hover:not(:disabled) { background: var(--red-soft); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---------- Cards / panels ---------- */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2, .panel-header h3 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink-900);
}

.panel-body { padding: 20px; }

/* ---------- Metric tiles ---------- */
.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.metric-tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}

.metric-tile::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
}

.metric-tile.tone-amber::before { background: var(--amber); }
.metric-tile.tone-blue::before { background: var(--blue); }
.metric-tile.tone-red::before { background: var(--red); }

.metric-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-400);
  font-weight: 600;
  margin-bottom: 8px;
}

.metric-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--ink-900);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.metric-skel {
  height: 24px;
  width: 60px;
  border-radius: 4px;
  background: linear-gradient(90deg, #eceef1 25%, #dfe2e7 50%, #eceef1 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-600);
  margin-bottom: 5px;
}

.field .hint {
  font-size: 11.5px;
  color: var(--ink-400);
  margin-top: 4px;
}

.input, select.input {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  color: var(--ink-800);
  background: var(--card);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.input:focus, select.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 92, 0.12);
}

.input-icon-wrap { position: relative; }
.input-icon-wrap .ic {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-400);
  font-size: 12px;
}
.input-icon-wrap .input { padding-left: 30px; }

/* ---------- Search / filter bar ---------- */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

@media (max-width: 1100px) {
  .filter-bar { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .filter-bar { grid-template-columns: 1fr; }
}

.filter-actions-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ---------- Table ---------- */
.data-table-wrap { position: relative; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.8px;
  table-layout: fixed;
}

.data-table thead th {
  text-align: left;
  background: var(--paper);
  color: var(--ink-500);
  font-size: 10.8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-700);
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table tbody tr:hover { background: var(--paper); }
.data-table tbody tr:last-child td { border-bottom: none; }

.cell-muted { color: var(--ink-400); }
.cell-strong { font-weight: 600; color: var(--ink-900); }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
}

.pill-accent { background: var(--accent-soft); color: var(--accent-ink); }
.pill-blue { background: var(--blue-soft); color: #1d3f70; }
.pill-neutral { background: var(--ink-100); color: var(--ink-500); }
.pill-amber { background: var(--amber-soft); color: #6e4013; }
.pill-red { background: var(--red-soft); color: #7a2727; }

.status-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 6px;
}
.status-dot.on { background: #2f9e6f; }
.status-dot.off { background: var(--ink-300); }
.status-dot.hold { background: var(--red); }

/* ---------- Column filter dropdown ---------- */
.th-filter { display: inline-flex; align-items: center; gap: 5px; position: relative; }

.th-filter-btn {
  border: none;
  background: transparent;
  color: var(--ink-300);
  cursor: pointer;
  font-size: 10.5px;
  padding: 2px;
  border-radius: 3px;
}
.th-filter-btn:hover { color: var(--ink-600); background: var(--ink-100); }
.th-filter-btn.on { color: var(--accent); background: var(--accent-soft); }

.th-filter-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  min-width: 170px;
  padding: 4px 0;
  z-index: 40;
  text-transform: none;
  letter-spacing: normal;
}
.th-filter-menu.open { display: block; }

.th-filter-opt {
  padding: 7px 13px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-700);
  cursor: pointer;
}
.th-filter-opt:hover { background: var(--paper); }
.th-filter-opt.sel { color: var(--accent-dark); font-weight: 700; }

/* ---------- Toggle switch ---------- */
.switch-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--ink-500);
  cursor: pointer;
  user-select: none;
}
.switch-label input { display: none; }
.switch-track {
  width: 30px; height: 16px;
  border-radius: 9px;
  background: var(--ink-200);
  position: relative;
  transition: background 0.15s ease;
  flex-shrink: 0;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  transition: transform 0.15s ease;
}
.switch-label input:checked + .switch-track { background: var(--accent); }
.switch-label input:checked + .switch-track::after { transform: translateX(14px); }

/* ---------- Empty / loading / error states ---------- */
.state-block {
  text-align: center;
  padding: 56px 20px;
}
.state-icon {
  font-size: 30px;
  color: var(--ink-200);
  margin-bottom: 14px;
}
.state-title { font-size: 14px; font-weight: 700; color: var(--ink-700); margin-bottom: 4px; }
.state-text { font-size: 12.5px; color: var(--ink-400); margin-bottom: 16px; }

.table-loading-veil {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.85);
  align-items: flex-start;
  justify-content: center;
  padding-top: 70px;
  backdrop-filter: blur(1px);
  z-index: 30;
}
.table-loading-veil.show { display: flex; }

.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.spinner-sm {
  width: 12px; height: 12px;
  border-width: 2px;
  display: inline-block;
  vertical-align: -1px;
}

/* ---------- Pagination ---------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-400);
}
.pager-controls { display: flex; gap: 4px; }
.pager-btn {
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-600);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.pager-btn:hover:not(.disabled):not(.active) { background: var(--paper); }
.pager-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pager-btn.disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- API key value / copy ---------- */
.key-chip {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-700);
}
.key-chip:hover { border-color: var(--accent); color: var(--accent-dark); }
.key-chip .ic { font-size: 10.5px; color: var(--ink-300); }

.toast-stack {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--ink-900);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: var(--shadow-2);
  min-width: 200px;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 20, 0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: var(--card);
  border-radius: var(--radius-lg);
  width: 420px;
  max-width: 92vw;
  box-shadow: var(--shadow-2);
  padding: 22px;
}
.modal-box h3 { margin: 0 0 8px; font-size: 15px; }
.modal-box p { margin: 0 0 18px; font-size: 13px; color: var(--ink-500); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Auth (login) ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink-950);
  padding: 20px;
}
.auth-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 34px 32px;
  width: 380px;
  max-width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}
.auth-title { font-size: 18px; font-weight: 700; color: var(--ink-900); margin-bottom: 4px; }
.auth-subtitle { font-size: 12.5px; color: var(--ink-400); margin-bottom: 22px; }

/* ---------- Misc ---------- */
.text-link { color: var(--accent); font-weight: 600; cursor: pointer; }
.text-link:hover { text-decoration: underline; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-gap { display: flex; align-items: center; gap: 8px; }

.responsive-scroll { overflow-x: auto; }

@media (max-width: 900px) {
  .app-sidebar { position: fixed; z-index: 100; transform: translateX(-100%); transition: transform 0.2s ease; }
  .app-sidebar.open { transform: translateX(0); }
  .app-content { padding: 18px; }
  .app-topbar { padding: 14px 18px; }
}
