/* ===== ERM Design System — Dark + Light Theme ===== */

:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --surface-secondary: #f9fafb;
  --surface-hover: #f3f4f6;
  --border: #e5e7eb;
  --border-light: #d1d5db;
  --text: #111827;
  --text-muted: #6B7280;
  --text-subtle: #9CA3AF;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-active: #4338ca;
  --accent-light: rgb(99 102 241 / 0.08);
  --positive: #16a34a;
  --positive-bg: rgb(34 197 94 / 0.1);
  --negative: #dc2626;
  --negative-bg: rgb(239 68 68 / 0.1);
  --warning: #ca8a04;
  --warning-bg: rgb(234 179 8 / 0.1);
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px -4px rgba(0,0,0,0.1);
  --shadow-xl: 0 20px 60px -12px rgba(0,0,0,0.15);
  --input-bg: #ffffff;
  --hover-bg: #f3f4f6;
  --skeleton-from: #e5e7eb;
  --skeleton-mid: #f3f4f6;
  --overlay: rgba(0,0,0,0.3);
}

[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d2e;
  --surface-secondary: #161822;
  --surface-hover: #1f2237;
  --border: #2a2d3e;
  --border-light: #333750;
  --text: #e2e4e9;
  --text-muted: #8890a0;
  --text-subtle: #636880;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-active: #4338ca;
  --accent-light: rgb(99 102 241 / 0.12);
  --positive: #22c55e;
  --positive-bg: rgb(34 197 94 / 0.12);
  --negative: #ef4444;
  --negative-bg: rgb(239 68 68 / 0.12);
  --warning: #eab308;
  --warning-bg: rgb(234 179 8 / 0.12);
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px -4px rgba(0,0,0,0.4);
  --shadow-xl: 0 20px 60px -12px rgba(0,0,0,0.5);
  --input-bg: #0f1117;
  --hover-bg: rgb(255 255 255 / 0.04);
  --skeleton-from: #1a1d2e;
  --skeleton-mid: #1f2237;
  --overlay: rgba(0,0,0,0.6);
}

/* Page visibility */
.page { display: none; }
.page.active { display: block; animation: pageFadeIn 0.35s ease-out; }
#login-screen.active { display: flex; }

/* Body */
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0; min-height: 100vh;
  transition: background-color 0.3s, color 0.3s;
}

/* Animations */
@keyframes pageFadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes statPop {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Sidebar */
aside {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  display: flex; flex-direction: column; width: 14rem;
  background: var(--surface-secondary); border-right: 1px solid var(--border);
  transition: background-color 0.3s, border-color 0.3s;
}
aside .text-lg { color: var(--text); }
aside .text-xs { color: var(--text-muted); }
aside .border-t { border-color: var(--border); }

.nav-item {
  color: var(--text-muted); transition: all 0.15s ease;
}
.nav-item:hover { color: var(--text); background: var(--hover-bg); }
.nav-item.active {
  color: var(--accent);
  background: var(--accent-light);
}

main {
  margin-left: 14rem; padding: 2rem;
  max-width: calc(14rem + 1280px);
}

/* Typography */
h1, .text-2xl { font-size: 2.25rem; font-weight: 700; letter-spacing: -0.025em; color: var(--text); }
h2, .text-xl { font-size: 1.5rem; font-weight: 600; color: var(--text); }
.text-muted, .text-sm.text-muted { color: var(--text-muted); }
.stat-value, .mono { font-family: 'JetBrains Mono', 'Cascadia Code', monospace; }

/* Buttons */
.btn-primary {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.625rem 1.25rem; background: var(--accent); color: white;
  border: none; border-radius: 8px; font-size: 0.875rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s ease; white-space: nowrap;
}
.btn-primary:hover {
  background: var(--accent-hover); transform: translateY(-1px);
  box-shadow: 0 4px 12px rgb(99 102 241 / 0.3);
}
.btn-primary:active { background: var(--accent-active); transform: translateY(0); box-shadow: none; }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.625rem 1.25rem; background: transparent; color: var(--text-muted);
  border: 1.5px solid var(--border-light); border-radius: 8px; font-size: 0.875rem; font-weight: 500;
  cursor: pointer; transition: all 0.15s ease; white-space: nowrap;
}
.btn-secondary:hover { color: var(--text); border-color: var(--accent); background: var(--accent-light); }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 0.375rem;
  padding: 0.375rem 0.75rem; background: transparent; color: var(--text-muted);
  border: 1px solid transparent; border-radius: 6px; font-size: 0.75rem;
  cursor: pointer; transition: all 0.15s ease;
}
.btn-ghost:hover { color: var(--text); background: var(--hover-bg); }
.btn-ghost:active { transform: translateY(1px); }
.btn-ghost.danger:hover { color: var(--negative); background: var(--negative-bg); }

.btn-cancel {
  display: inline-flex; align-items: center;
  padding: 0.625rem 1.25rem; background: transparent; color: var(--text-muted);
  border: 1px solid var(--border-light); border-radius: 8px; font-size: 0.875rem;
  cursor: pointer; transition: all 0.15s ease;
}
.btn-cancel:hover { color: var(--text); border-color: var(--text-subtle); }

/* Theme Toggle */
.theme-toggle {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.375rem; background: var(--hover-bg);
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; transition: all 0.2s;
  color: var(--text-muted); font-size: 0.75rem;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--text); }
.theme-toggle svg { width: 16px; height: 16px; }

/* Panels & Cards */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 1.5rem;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s, background-color 0.3s;
}
.panel:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 1.25rem;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s, background-color 0.3s;
  animation: statPop 0.48s ease-out both;
}
.stat-card:hover {
  border-color: var(--accent);
  transform: scale(1.03) translateY(-1px);
  box-shadow: var(--shadow-lg);
}
.stat-card:nth-child(1) { animation-delay: 0s; }
.stat-card:nth-child(2) { animation-delay: 0.1s; }
.stat-card:nth-child(3) { animation-delay: 0.2s; }
.stat-card:nth-child(4) { animation-delay: 0.3s; }
.stat-card:nth-child(5) { animation-delay: 0.4s; }
.stat-card:nth-child(6) { animation-delay: 0.5s; }
.stat-card .stat-label {
  font-size: 0.688rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.375rem;
  font-weight: 500;
}
.stat-card .stat-value {
  font-size: 1.625rem; font-weight: 700; line-height: 1.2; color: var(--text);
}
.stat-card .stat-sub {
  font-size: 0.75rem; color: var(--text-subtle); margin-top: 0.25rem;
}

/* Table */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
  transition: background-color 0.3s, border-color 0.3s;
}
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table-wrap thead {
  background: var(--surface-secondary); border-bottom: 1px solid var(--border);
}
.table-wrap th {
  text-align: left; padding: 0.75rem 1rem; color: var(--text-muted);
  font-weight: 500; font-size: 0.688rem; text-transform: uppercase;
  letter-spacing: 0.05em; white-space: nowrap;
}
.table-wrap td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); color: var(--text); }
.table-wrap tbody tr:last-child td { border-bottom: none; }
.table-wrap tbody tr:hover td { background: var(--surface-hover); }

/* Bulk action bar */
.bulk-bar {
  display: none; align-items: center; gap: 0.75rem;
  padding: 0.625rem 1rem; background: var(--accent);
  color: white; border-radius: 8px; margin-bottom: 0.75rem;
  font-size: 0.8125rem; font-weight: 500;
}
.bulk-bar.active { display: flex; }
.bulk-bar .btn-bulk {
  padding: 0.25rem 0.625rem; background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3); border-radius: 4px;
  color: white; font-size: 0.75rem; cursor: pointer;
  transition: background 0.15s;
}
.bulk-bar .btn-bulk:hover { background: rgba(255,255,255,0.3); }
.bulk-bar .btn-bulk.danger { background: var(--negative); border-color: var(--negative); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; padding: 2px 10px;
  border-radius: 9999px; font-size: 0.688rem; font-weight: 500; white-space: nowrap;
}
.badge-active, .badge-paid, .badge-done, .badge-completed {
  background: var(--positive-bg); color: var(--positive);
}
.badge-pending, .badge-progress, .badge-in_progress {
  background: var(--warning-bg); color: var(--warning);
}
.badge-unpaid, .badge-todo, .badge-overdue {
  background: var(--negative-bg); color: var(--negative);
}
.badge-cancelled, .badge-inactive {
  background: var(--hover-bg); color: var(--text-muted);
}

/* Kanban */
.kanban-col {
  background: var(--surface-secondary); border: 1px solid var(--border);
  border-radius: 8px; padding: 1rem; min-height: 200px;
  transition: background-color 0.3s, border-color 0.2s;
}
.kanban-col.drag-over {
  border-color: var(--accent); background: var(--accent-light);
}
.kanban-col h4 { color: var(--text); font-weight: 600; }
.task-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.75rem; font-size: 0.8125rem; color: var(--text);
  cursor: grab; transition: all 0.2s ease;
}
.task-card:active { cursor: grabbing; }
.task-card.dragging {
  opacity: 0.5; border-style: dashed;
}
.task-card:hover {
  border-color: var(--accent);
  transform: scale(1.02) translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.task-card:active { transform: scale(1) translateY(0); }
.task-card .task-priority {
  font-size: 0.688rem; color: var(--text-subtle); margin-top: 0.375rem;
}

/* Modal */
#modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: var(--overlay); display: flex;
  align-items: center; justify-content: center;
  padding: 1.5rem;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 1.75rem; width: 100%; max-width: 480px;
  box-shadow: var(--shadow-xl);
  animation: modalIn 0.2s ease-out;
  transition: background-color 0.3s;
}

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block; font-size: 0.688rem; color: var(--text-muted);
  margin-bottom: 0.375rem; text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 500;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 0.625rem 0.75rem; background: var(--input-bg);
  border: 1px solid var(--border-light); border-radius: 6px; color: var(--text);
  font-size: 0.875rem; font-family: inherit; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.3s, color 0.3s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgb(99 102 241 / 0.12);
}
.form-group textarea { min-height: 80px; resize: vertical; }
.form-group select {
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236B7280' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19.5 8.25l-7.5 7.5-7.5-7.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.625rem center;
  background-size: 1rem; padding-right: 2.25rem;
}
.form-actions {
  display: flex; gap: 0.625rem; justify-content: flex-end;
  margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border);
}

/* Empty State */
.empty {
  text-align: center; color: var(--text-subtle); padding: 2rem 1rem; font-size: 0.875rem;
}

/* List items */
.list-item { padding: 0.75rem 0; color: var(--text); }
.list-item + .list-item { border-top: 1px solid var(--border); }

/* Search */
#global-search {
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text);
  transition: background-color 0.3s, border-color 0.3s, color 0.3s;
}
#global-search::placeholder { color: var(--text-subtle); }
#global-search:focus { border-color: var(--accent); background: var(--surface); }
#search-results {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow-lg);
}
.search-result-item {
  display: flex; align-items: center; gap: 0.625rem;
  padding: 0.5rem 0.75rem; cursor: pointer; font-size: 0.8125rem;
  transition: background 0.1s; color: var(--text);
}
.search-result-item:hover { background: var(--accent-light); }
.search-result-item .sr-type {
  font-size: 0.625rem; text-transform: uppercase; padding: 0.0625rem 0.375rem;
  border-radius: 4px; font-weight: 600;
}

/* Calendar */
.cal-day-header {
  text-align: center; padding: 0.5rem; font-size: 0.688rem;
  font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em;
}
.cal-cell {
  min-height: 80px; padding: 0.375rem; background: var(--surface);
  font-size: 0.75rem; cursor: pointer; transition: background 0.1s;
  border: 1px solid var(--border);
}
.cal-cell:hover { background: var(--surface-hover); }
.cal-cell.today { background: var(--accent-light); }
.cal-cell.other-month { opacity: 0.3; }
.cal-cell .cal-date { display: inline-block; width: 1.5rem; height: 1.5rem; line-height: 1.5rem; text-align: center; border-radius: 9999px; margin-bottom: 0.25rem; color: var(--text); }
.cal-cell.today .cal-date { background: var(--accent); color: white; font-weight: 600; }
.cal-event-dot {
  display: block; font-size: 0.625rem; padding: 0.0625rem 0.25rem;
  border-radius: 3px; margin-top: 0.125rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Progress bar */
.progress-bar {
  height: 8px; background: var(--border); border-radius: 9999px; overflow: hidden; margin-top: 0.5rem;
}
.progress-bar .progress-fill {
  height: 100%; border-radius: 9999px; transition: width 0.5s ease;
}

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--skeleton-from) 25%, var(--skeleton-mid) 50%, var(--skeleton-from) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 4px;
}

/* Toast */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 500;
  padding: 0.75rem 1.25rem; border-radius: 8px; font-size: 0.875rem;
  box-shadow: var(--shadow-xl);
  animation: toastIn 0.3s ease-out; max-width: 360px;
}
.toast-success { background: var(--positive-bg); border: 1px solid rgba(34,197,94,0.2); color: var(--positive); }
.toast-error { background: var(--negative-bg); border: 1px solid rgba(239,68,68,0.2); color: var(--negative); }

/* Tabs */
.tab {
  padding: 0.5rem 1rem; font-size: 0.8125rem; color: var(--text-muted);
  border-bottom: 2px solid transparent; cursor: pointer;
  transition: all 0.15s; font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Activity log */
.activity-item {
  padding: 0.625rem 0; border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
}
.activity-item:last-child { border-bottom: none; }
.activity-time { color: var(--text-subtle); font-size: 0.688rem; }

/* Responsive */
@media (max-width: 768px) {
  aside { width: 3.5rem !important; }
  aside .text-lg, aside .nav-item span, aside .text-xs, aside .border-t,
  aside #global-search, aside #search-results, aside .px-3.pt-3,
  aside .theme-toggle span { display: none !important; }
  aside .nav-item { justify-content: center; padding: 0.5rem; }
  aside nav { padding-left: 0.25rem; padding-right: 0.25rem; }
  main { margin-left: 3.5rem !important; padding: 1rem; }
  .grid-cols-2.lg\:grid-cols-4, .grid-cols-2.lg\:grid-cols-5,
  .grid-cols-2.xl\:grid-cols-7,
  .grid-cols-2.md\:grid-cols-4, .grid-cols-2.md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-cols-1.lg\:grid-cols-2 { grid-template-columns: 1fr; }
  .grid-cols-1.md\:grid-cols-3 { grid-template-columns: 1fr; }
  .grid-cols-1.md\:grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-cols-1.md\:grid-cols-2 { grid-template-columns: 1fr; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 600px; font-size: 0.8125rem; }
  .table-wrap th, .table-wrap td { padding: 0.5rem 0.625rem; white-space: nowrap; }
  @media (max-width: 639px) {
    .table-wrap table, .table-wrap thead, .table-wrap tbody, 
    .table-wrap th, .table-wrap tr, .table-wrap td { display: block; }
    .table-wrap thead { display: none; }
    .table-wrap tr {
      background: var(--surface); border: 1px solid var(--border);
      border-radius: 8px; padding: 0.75rem; margin-bottom: 0.75rem;
    }
    .table-wrap tr:hover { background: var(--surface-hover); }
    .table-wrap td {
      padding: 0.375rem 0.375rem 0.375rem 42%;
      position: relative; min-height: 1.5rem; white-space: normal;
      border-bottom: 1px solid var(--border); font-size: 0.8125rem;
    }
    .table-wrap td:last-child { border-bottom: none; }
    .table-wrap td::before {
      content: attr(data-label);
      position: absolute; left: 0.75rem; width: 35%;
      font-size: 0.625rem; font-weight: 600; color: var(--text-muted);
      text-transform: uppercase; letter-spacing: 0.05em;
      padding-right: 0.5rem; white-space: nowrap;
      overflow: hidden; text-overflow: ellipsis;
    }
    .table-wrap table { min-width: 0; }
  }
  .page-header, .flex.items-center.justify-between {
    flex-direction: column; align-items: flex-start; gap: 0.75rem;
  }
  .page-header button, .flex.items-center.justify-between button { width: 100%; justify-content: center; }
  h1, .text-2xl { font-size: 1.25rem !important; }
  .modal { margin: 0; max-height: 100vh; border-radius: 0; width: 100%; padding: 1.25rem; }
  #modal-overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 95vh; }
  .stat-card { padding: 0.875rem; }
  .stat-card .stat-value { font-size: 1.25rem; }
  .cal-cell { min-height: 50px; font-size: 0.625rem; padding: 0.125rem; }
  .cal-cell .cal-date { width: 1.25rem; height: 1.25rem; line-height: 1.25rem; font-size: 0.625rem; }
  .cal-event-dot { display: none; }
  .cal-day-header { font-size: 0.5625rem; padding: 0.25rem; }
  .kanban-col { min-height: 120px; padding: 0.75rem; }
  .grid-cols-2 { grid-template-columns: 1fr; }
  .form-actions { flex-direction: column; }
  .form-actions button { width: 100%; justify-content: center; }
  .toast { left: 1rem; right: 1rem; max-width: none; bottom: 1rem; }
  .panel { padding: 1rem; }
  #login-screen .max-w-sm { max-width: 100%; padding: 0 1rem; }
  #login-screen .panel { padding: 1.25rem; }
}

@media (max-width: 480px) {
  .stat-card { padding: 0.75rem 0.625rem; }
  .stat-card .stat-value { font-size: 1.125rem; }
  .stat-card .stat-label { font-size: 0.5625rem; }
  .table-wrap table { min-width: 450px; font-size: 0.75rem; }
  .grid-cols-2 { grid-template-columns: 1fr 1fr; }
  .page h1 + p, .text-sm.text-muted.mt-1 { display: none; }
  .kanban-col h4 { font-size: 0.625rem; }
}
