@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root,
html[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-subtle: #e8edf4;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --surface-hover: #f8fafc;
  --text: #0f172a;
  --text-secondary: #334155;
  --muted: #64748b;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: #eff6ff;
  --accent-muted: #93c5fd;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --ok: #059669;
  --ok-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.05);
  --radius: 10px;
  --radius-lg: 14px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --sidebar-w: 256px;
  --topbar-h: 64px;
  --gradient-brand: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 50%, #2563eb 100%);
}

html[data-theme="dark"] {
  --bg: #09090b;
  --bg-subtle: #0f1117;
  --surface: #111318;
  --surface-elevated: #181b22;
  --surface-hover: #1c2029;
  --text: #f8fafc;
  --text-secondary: #cbd5e1;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft: #172554;
  --accent-muted: #1e3a8a;
  --border: #1e293b;
  --border-strong: #334155;
  --danger: #f87171;
  --danger-bg: #2a1515;
  --ok: #34d399;
  --ok-bg: #0f2922;
  --warning: #fbbf24;
  --warning-bg: #2a2210;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 32px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html { color-scheme: light; scroll-behavior: smooth; }
html[data-theme="dark"] { color-scheme: dark; }

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

a { color: var(--accent); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--accent-hover); }

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--text);
  line-height: 1.25;
}

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1.25rem 1.25rem 1rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.03em;
}

.sidebar-brand:hover { color: var(--text); }

.site-logo {
  display: block;
  height: 36px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
}

/* Dark logos stay readable on dark UI without a second upload */
html[data-theme="dark"] .site-logo {
  filter: brightness(0) invert(1);
}

/* Login left panel is always dark — keep logo light there even in light theme */
.login-brand-panel .site-logo {
  filter: brightness(0) invert(1);
}

.brand-text {
  line-height: 1;
}

.sidebar-badge {
  display: block;
  margin: 0 1.25rem 0.75rem;
  padding: 0.35rem 0.6rem;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.sidebar-nav {
  flex: 1;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow-y: auto;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}

.sidebar-link:hover { background: var(--surface-hover); color: var(--text); }

.sidebar-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.sidebar-link.active svg { opacity: 1; }

.sidebar-footer {
  padding: 1rem 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

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

.app-topbar {
  height: var(--topbar-h);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.app-content {
  flex: 1;
  padding: 1.75rem 2rem 2.5rem;
  max-width: 1200px;
  width: 100%;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.page-header h1 { font-size: 1.375rem; }

.ui-chrome { display: flex; align-items: center; gap: 0.5rem; }

.lang-switch {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.lang-switch a {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  line-height: 1;
}

.lang-switch a.active {
  color: var(--accent);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.lang-switch a:hover:not(.active) { color: var(--text); }

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
}

.theme-toggle-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.theme-toggle-btn svg { width: 16px; height: 16px; }

.card {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

input, select, textarea {
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  min-height: 42px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}

.toggle-row:last-child { border-bottom: none; }

.toggle-row input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  min-height: auto;
  accent-color: var(--accent);
}

.time-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 1rem;
  min-height: 40px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  text-decoration: none;
}

.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--accent-hover); color: #fff; box-shadow: var(--shadow-sm); }

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-outline:hover { background: var(--surface-hover); border-color: var(--muted); color: var(--text); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); background: var(--surface-hover); border-color: var(--border-strong); }

.btn-lg { min-height: 46px; padding: 0 1.35rem; font-size: 0.875rem; }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }

th, td {
  text-align: left;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

th {
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-hover); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat {
  background: var(--surface);
  padding: 1.15rem 1.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.stat .num {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.stat .lbl {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  margin-top: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: capitalize;
}
.badge-paid, .badge-running { background: var(--ok-bg); color: var(--ok); }
.badge-pending { background: var(--warning-bg); color: var(--warning); }
.badge-overdue, .badge-stopped { background: var(--danger-bg); color: var(--danger); }

.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  border: 1px solid transparent;
}
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--danger-bg); color: var(--danger); }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.inline { display: inline; }
.muted { color: var(--muted); }

.section-block { margin-bottom: 2rem; }
.section-block > h2 { font-size: 0.95rem; margin-bottom: 0.85rem; color: var(--text-secondary); }

.command-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.command-card h3 { margin: 0 0 0.6rem; font-size: 0.95rem; }
.command-card ul { margin: 0; padding-left: 1.1rem; color: var(--muted); font-size: 0.875rem; }
.command-card li { margin: 0.35rem 0; }

.prose article { background: var(--surface); padding: 1.5rem; border-radius: var(--radius-lg); border: 1px solid var(--border); }
.doc-list { list-style: none; padding: 0; }

.tabs {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 0.65rem 1rem;
  margin-bottom: -1px;
  cursor: pointer;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  min-height: 40px;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-panel { display: none; }
.tab-panel.active { display: grid; gap: 0.85rem; }

.section-title {
  margin: 1.25rem 0 0.65rem;
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.message-thread {
  display: grid;
  gap: 0.85rem;
  max-width: 720px;
}

.message-bubble {
  padding: 1rem 1.1rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.message-bubble.admin,
.message-bubble.system {
  border-left: 3px solid var(--accent);
}

.message-bubble.customer {
  border-left: 3px solid var(--ok);
}

.message-bubble header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.message-bubble header strong {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.message-body {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

textarea {
  min-height: 100px;
  resize: vertical;
}

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; padding: 0 0.75rem 0.5rem; }
  .sidebar-footer { display: none; }
  .app-content { padding: 1.25rem 1rem 2rem; }
}
