:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --sidebar: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #ffffff;
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --success: #059669;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: var(--font); color: var(--text); background: var(--bg); }

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

.sidebar {
  width: 240px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 1.25rem 0.75rem;
  flex-shrink: 0;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.5rem 0.75rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 1rem;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.brand strong { color: #fff; display: block; }
.brand small { color: var(--sidebar-text); font-size: 0.75rem; }

.nav { display: flex; flex-direction: column; gap: 0.25rem; }

.nav-btn {
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.92rem;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover { background: rgba(255,255,255,0.06); color: #e2e8f0; }
.nav-btn.active { background: rgba(13, 148, 136, 0.2); color: var(--sidebar-active); }

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.topbar h1 { margin: 0; font-size: 1.35rem; }
.muted { color: var(--muted); margin: 0.25rem 0 0; font-size: 0.9rem; }

.company-select {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.company-select select {
  min-width: 220px;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}

.content { padding: 1.5rem; flex: 1; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 900px) {
  .sidebar { width: 200px; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

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

.card h3 { margin: 0 0 0.75rem; font-size: 1rem; }

.stat-value { font-size: 1.75rem; font-weight: 700; margin: 0.25rem 0; }
.stat-label { color: var(--muted); font-size: 0.85rem; }

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

.panel-header h2 { margin: 0; font-size: 1.1rem; }

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }

.form-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid .full { grid-column: 1 / -1; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

input, select, textarea {
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
}

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

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-danger { background: #fee2e2; color: var(--danger); }

.btn-icon {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #e2e8f0;
  color: #475569;
}

.badge.ok { background: #d1fae5; color: var(--success); }
.badge.warn { background: #fef3c7; color: #b45309; }

.empty {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

.split { display: grid; grid-template-columns: 340px 1fr; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-panel {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  width: min(720px, 100%);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 1.25rem; overflow-y: auto; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--sidebar);
  color: white;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 200;
  max-width: 360px;
}

.toast.error { background: var(--danger); }
.toast.hidden { display: none; }

.text-right { text-align: right; }
.mono { font-family: ui-monospace, monospace; font-size: 0.82rem; }
