:root {
  --color-bg: #f5f6fa;
  --color-surface: #ffffff;
  --color-surface-2: #f9fafb;
  --color-border: #e5e7eb;
  --color-text: #0f172a;
  --color-text-muted: #475569;
  --color-text-faint: #6b7280;
  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-primary-soft: #eef2ff;
  --color-success: #16a34a;
  --color-success-soft: #dcfce7;
  --color-warning: #f59e0b;
  --color-warning-soft: #fef3c7;
  --color-danger: #dc2626;
  --color-danger-soft: #fee2e2;
  --color-info: #0284c7;
  --color-info-soft: #e0f2fe;
  --color-accent: #fbbf24;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --sidebar-w: 240px;
  --topbar-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Menlo, Consolas, monospace;
  --transition: 160ms cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
  --color-bg: #0b1020;
  --color-surface: #111831;
  --color-surface-2: #0e1428;
  --color-border: #1f2a44;
  --color-text: #e2e8f0;
  --color-text-muted: #cbd5e1;
  --color-text-faint: #94a3b8;
  --color-primary: #818cf8;
  --color-primary-hover: #6366f1;
  --color-primary-soft: #1e1f4b;
  --color-success-soft: #052e16;
  --color-warning-soft: #422006;
  --color-danger-soft: #450a0a;
  --color-info-soft: #082f49;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.6; }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
input::placeholder, textarea::placeholder { color: var(--color-text-faint); }

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; color: var(--color-text); }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }
hr { border: none; border-top: 1px solid var(--color-border); margin: 8px 0; }
.hidden { display: none !important; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  background: var(--color-surface-2);
  color: var(--color-text);
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--color-border); }
.btn-primary {
  background: var(--color-primary);
  color: #ffffff;
  border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-border); color: var(--color-text); }
.btn-danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-outline { background: transparent; border-color: var(--color-border); }
.btn-outline:hover { background: var(--color-surface-2); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-icon { padding: 6px 8px; }

.icon-btn {
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 18px;
  transition: background var(--transition);
}
.icon-btn:hover { background: var(--color-surface-2); color: var(--color-text); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.badge-success { background: var(--color-success-soft); color: var(--color-success); border-color: transparent; }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); border-color: transparent; }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); border-color: transparent; }
.badge-info { background: var(--color-info-soft); color: var(--color-info); border-color: transparent; }
.badge-primary { background: var(--color-primary-soft); color: var(--color-primary); border-color: transparent; }
.badge-dot::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  margin-right: 4px;
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12px; font-weight: 500; color: var(--color-text-muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #ec4899 100%);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand h1 { font-size: 24px; margin-top: 12px; }
.auth-sub { color: var(--color-text-muted); font-size: 14px; margin-top: 4px; }
.auth-logo svg { display: block; margin: 0 auto; }
.auth-tabs { display: flex; background: var(--color-surface-2); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 20px; }
.auth-tab { flex: 1; background: transparent; border: none; padding: 8px; border-radius: var(--radius-sm); font-weight: 500; color: var(--color-text-muted); }
.auth-tab.active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-sm); }
.auth-form { display: flex; flex-direction: column; }
.auth-error { color: var(--color-danger); font-size: 13px; min-height: 18px; margin-top: 4px; }
.auth-hint { color: var(--color-text-faint); font-size: 12px; text-align: center; margin-top: 12px; }

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--color-border);
  min-height: var(--topbar-h);
}
.brand-logo { flex: 0 0 auto; }
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--color-text-muted); }
.nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  text-decoration: none;
}
.nav-link:hover { background: var(--color-surface-2); color: var(--color-text); text-decoration: none; }
.nav-link.active { background: var(--color-primary-soft); color: var(--color-primary); }
.nav-icon { width: 18px; text-align: center; font-size: 16px; }
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sync-indicator { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--color-text-muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-online { background: var(--color-success); box-shadow: 0 0 0 3px var(--color-success-soft); }
.dot-offline { background: var(--color-text-faint); }
.dot-syncing { background: var(--color-info); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; }
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 15;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 18px; }
.topbar-sub { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.search-box { position: relative; width: 320px; max-width: 30vw; }
.search-box input { padding-left: 32px; background: var(--color-surface-2); }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--color-text-faint); }
.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 40;
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
}
.search-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.search-dropdown-item:hover, .search-dropdown-item:focus { background: var(--color-surface-2); }
.search-dropdown-type {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-primary);
  background: var(--color-primary-soft);
  padding: 1px 6px;
  border-radius: 4px;
  flex: 0 0 auto;
}
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; background: transparent; border: none; padding: 4px 8px; border-radius: var(--radius-sm); color: var(--color-text); }
.user-btn:hover { background: var(--color-surface-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--color-primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; }
.user-name { font-size: 13px; font-weight: 500; }
.caret { font-size: 10px; color: var(--color-text-muted); }
.user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  min-width: 200px;
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: 30;
}
.user-dropdown a, .user-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: 14px;
}
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--color-surface-2); text-decoration: none; }

.content { padding: 24px; max-width: 1400px; }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header h1 { font-size: 22px; }
.page-actions { display: flex; gap: 8px; }

.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.metric-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 18px; box-shadow: var(--shadow-sm); }
.metric-label { font-size: 12px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.metric-value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.metric-delta { font-size: 12px; margin-top: 4px; }
.metric-delta.up { color: var(--color-success); }
.metric-delta.down { color: var(--color-danger); }
.metric-icon { float: right; font-size: 24px; opacity: 0.6; }

.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--color-border); }
.card-header h2, .card-header h3 { font-size: 15px; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.grid-equal-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.empty-state { padding: 48px 24px; text-align: center; color: var(--color-text-muted); }
.empty-state .empty-icon { font-size: 40px; opacity: 0.5; margin-bottom: 8px; }
.empty-state h3 { color: var(--color-text); margin-bottom: 4px; }
.empty-state p { margin-bottom: 16px; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .search-box { width: 280px; max-width: 100%; }
.toolbar select { width: auto; min-width: 140px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--color-border); font-size: 14px; }
th { font-size: 12px; font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; background: var(--color-surface-2); }
tr:hover td { background: var(--color-surface-2); }
td.actions, th.actions { text-align: right; white-space: nowrap; }
td.actions button { margin-left: 4px; }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--color-border); }
.list-item:last-child { border-bottom: none; }
.list-item .primary { font-weight: 500; }
.list-item .secondary { font-size: 12px; color: var(--color-text-muted); }
.list-icon { width: 36px; height: 36px; border-radius: 50%; background: var(--color-primary-soft); color: var(--color-primary); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; }

.progress { height: 6px; background: var(--color-border); border-radius: 999px; overflow: hidden; }
.progress > .bar { height: 100%; background: var(--color-primary); transition: width var(--transition); }
.progress.success > .bar { background: var(--color-success); }
.progress.warning > .bar { background: var(--color-warning); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; animation: fadein 150ms ease-out; }
.modal { background: var(--color-surface); border-radius: var(--radius-lg); max-width: 560px; width: 100%; max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: slidein 200ms ease-out; }
.modal.wide { max-width: 820px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--color-border); }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--color-border); background: var(--color-surface-2); }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.toast-container { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast { background: var(--color-surface); border: 1px solid var(--color-border); border-left: 4px solid var(--color-primary); border-radius: var(--radius-sm); padding: 10px 14px; box-shadow: var(--shadow-md); min-width: 240px; max-width: 360px; display: flex; align-items: center; gap: 8px; animation: slidein 200ms ease-out; }
.toast.success { border-left-color: var(--color-success); }
.toast.warning { border-left-color: var(--color-warning); }
.toast.danger { border-left-color: var(--color-danger); }
.toast .close { margin-left: auto; background: none; border: none; color: var(--color-text-muted); }

.timer-widget {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 25;
  min-width: 260px;
}
.timer-display { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 18px; font-weight: 600; }
.timer-pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--color-danger); animation: pulse 1.5s infinite; }
.timer-pulse.paused { background: var(--color-warning); animation: none; }
.timer-info { flex: 1; min-width: 0; }
.timer-task { font-size: 12px; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer-actions { display: flex; gap: 4px; }

.timer-card {
  background: linear-gradient(135deg, var(--color-primary) 0%, #7c3aed 100%);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.timer-card .timer-clock { font-family: var(--font-mono); font-size: 36px; font-weight: 700; letter-spacing: 0.02em; }
.timer-card .timer-task { color: rgba(255,255,255,0.9); }
.timer-card select, .timer-card input { background: rgba(255,255,255,0.15); color: #fff; border-color: rgba(255,255,255,0.25); }
.timer-card select option { color: var(--color-text); }
.timer-card .btn { background: rgba(255,255,255,0.2); color: #fff; border-color: transparent; }
.timer-card .btn:hover { background: rgba(255,255,255,0.3); }
.timer-card .btn-primary { background: #fff; color: var(--color-primary); }

.kbd { font-family: var(--font-mono); font-size: 11px; background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: 4px; padding: 1px 5px; color: var(--color-text-muted); }

.tab-bar { display: flex; gap: 4px; border-bottom: 1px solid var(--color-border); margin-bottom: 16px; }
.tab-bar button { background: transparent; border: none; padding: 10px 14px; color: var(--color-text-muted); font-weight: 500; border-bottom: 2px solid transparent; }
.tab-bar button.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.tab-bar button:hover { color: var(--color-text); }

.stat-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--color-border); font-size: 14px; }
.stat-row:last-child { border-bottom: none; }
.stat-row .label { color: var(--color-text-muted); }
.stat-row .value { font-weight: 600; }

.split-form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

@media (max-width: 1024px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-equal-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-100%); width: 240px; transition: transform 200ms ease; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.4); z-index: 19; animation: fadein 150ms ease-out; }
  .main { margin-left: 0; }
  .content { padding: 16px; }
  .topbar { padding: 0 12px; }
  .topbar-actions .search-box { display: none; }
  .user-name { display: none; }
  .grid-3 { grid-template-columns: 1fr; }
  .field-row, .field-row-3 { grid-template-columns: 1fr; }
  .split-form { grid-template-columns: 1fr; }
  .timer-widget { left: 12px; right: 12px; min-width: 0; }
  .mobile-menu-btn { display: inline-flex; }
  .metrics-grid { grid-template-columns: 1fr; }
}

@media (min-width: 769px) {
  .mobile-menu-btn { display: none; }
}

.chart-container { position: relative; height: 280px; }
.chart-container.tall { height: 360px; }

/* Skeleton loading */
@keyframes skeleton-pulse {
  0% { opacity: 0.4; }
  50% { opacity: 0.8; }
  100% { opacity: 0.4; }
}
.skeleton {
  background: linear-gradient(90deg, var(--color-border) 25%, var(--color-surface-2) 50%, var(--color-border) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
.skeleton-line { height: 12px; margin-bottom: 8px; width: 100%; }
.skeleton-line.w50 { width: 50%; }
.skeleton-line.w70 { width: 70%; }
.skeleton-line.w30 { width: 30%; }
.skeleton-box { height: 100px; width: 100%; }
.skeleton-card { padding: 20px; border-radius: var(--radius-md); background: var(--color-surface); border: 1px solid var(--color-border); }
.skeleton-metric { height: 80px; border-radius: var(--radius-md); background: var(--color-surface); border: 1px solid var(--color-border); padding: 16px; }
.skeleton-metric .skeleton-line { margin-bottom: 6px; }
.skeleton-table-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--color-border); }
@media (max-width: 768px) {
  .skeleton-table-row { grid-template-columns: 1fr 1fr; }
}

/* Skeleton layout for dashboard page */
.skeleton-dashboard .skeleton-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.skeleton-dashboard .skeleton-chart { height: 280px; margin-bottom: 20px; }
@media (max-width: 768px) {
  .skeleton-dashboard .skeleton-metrics { grid-template-columns: repeat(2, 1fr); }
}
