/* ================================================================
   Overtone — Base Stylesheet
   ================================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --clr-bg:       #f3f4f6;
  --clr-surface:  #ffffff;
  --clr-border:   #e5e7eb;
  --clr-text:     #111827;
  --clr-text-sec: #6b7280;
  --clr-text-dim: #9ca3af;
  --clr-primary:  #2563eb;
  --clr-primary-h:#1d4ed8;
  --clr-danger:   #dc2626;
  --clr-success:  #16a34a;
  --clr-warning:  #f59e0b;
  --clr-sidebar:  #1a1a2e;
  --clr-sidebar-t:#c4c4d4;
  --clr-sidebar-h:#2a2a4a;
  --sidebar-w:    240px;
  --header-h:     56px;
  --radius:       8px;
  --radius-sm:    5px;
  --shadow:       0 1px 3px rgba(0,0,0,.08);
  --shadow-lg:    0 8px 24px rgba(0,0,0,.14);
}

html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--clr-text);
  background: var(--clr-bg);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--clr-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

/* ----------------------------------------------------------------
   Layout — sidebar + main
   ---------------------------------------------------------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--clr-sidebar);
  color: var(--clr-sidebar-t);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: block;
  padding: 1.1rem 1.25rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.01em;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand:hover { color: #fff; text-decoration: none; }

.sidebar-nav { flex: 1; padding: .5rem 0; overflow-y: auto; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem 1.25rem;
  color: var(--clr-sidebar-t);
  font-size: .88rem;
  font-weight: 500;
  text-decoration: none;
  transition: background .12s, color .12s;
}
.sidebar-nav a:hover { background: var(--clr-sidebar-h); color: #fff; text-decoration: none; }
.sidebar-nav a.active { background: var(--clr-sidebar-h); color: #fff; }
.sidebar-nav .nav-icon { font-size: 1.15rem; width: 1.4rem; text-align: center; }
.sidebar-sep { height: 1px; background: rgba(255,255,255,.08); margin: .4rem 0; }

.sidebar-footer {
  padding: .75rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: .82rem;
}
.sidebar-footer a { color: var(--clr-sidebar-t); text-decoration: none; }
.sidebar-footer a:hover { color: #fff; }

.company-switch-form {
  margin: 0 0 .75rem 0;
}

.company-switch-label {
  display: block;
  margin-bottom: .3rem;
  color: rgba(255,255,255,.62);
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.company-switch-wrap {
  position: relative;
}

.company-switch-wrap::after {
  content: "";
  position: absolute;
  top: 50%;
  right: .65rem;
  width: .45rem;
  height: .45rem;
  border-right: 1px solid rgba(255,255,255,.62);
  border-bottom: 1px solid rgba(255,255,255,.62);
  transform: translateY(-68%) rotate(45deg);
  pointer-events: none;
}

.company-switch-select {
  width: 100%;
  min-height: 2.15rem;
  padding: .45rem 1.8rem .45rem .6rem;
  appearance: none;
  -webkit-appearance: none;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: .82rem;
  font-weight: 500;
  line-height: 1.25;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.03);
}

.company-switch-select:hover {
  background: rgba(255,255,255,.11);
  border-color: rgba(255,255,255,.22);
}

.company-switch-select:focus {
  outline: none;
  border-color: rgba(96,165,250,.95);
  box-shadow: 0 0 0 3px rgba(96,165,250,.22);
}

.company-switch-select option {
  color: var(--clr-text);
}

.company-switch-single {
  font-size: .78rem;
  margin-bottom: .75rem;
  color: rgba(255,255,255,.68);
  font-weight: 600;
}

.active-company-pill {
  display: inline-flex;
  align-items: center;
  max-width: 240px;
  padding: .18rem .55rem;
  border: 1px solid var(--clr-border);
  border-radius: 999px;
  color: var(--clr-text-sec);
  background: #f9fafb;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main-area {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ----------------------------------------------------------------
   Top header bar
   ---------------------------------------------------------------- */
.topbar {
  height: var(--header-h);
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 1.1rem; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: .75rem; }

.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--clr-text);
  padding: .25rem;
}

/* ----------------------------------------------------------------
   Page content
   ---------------------------------------------------------------- */
.page-content { padding: 1.5rem; flex: 1; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.25rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; }
.page-subtitle { color: var(--clr-text-sec); font-size: .9rem; margin-top: .15rem; }

/* ----------------------------------------------------------------
   Cards
   ---------------------------------------------------------------- */
.card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.card-header h2 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 1.25rem; }

/* ----------------------------------------------------------------
   KPI cards (dashboard)
   ---------------------------------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.kpi-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
}
.kpi-label {
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--clr-text-sec);
  margin-bottom: .35rem;
}
.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
}
.kpi-value.danger { color: var(--clr-danger); }
.kpi-value.warning { color: var(--clr-warning); }
.kpi-value.primary { color: var(--clr-primary); }
.kpi-value.success { color: var(--clr-success); }

/* ----------------------------------------------------------------
   Tables
   ---------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
.data-table th {
  text-align: left;
  padding: .65rem 1rem;
  font-size: .73rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--clr-text-sec);
  background: #f9fafb;
  border-bottom: 1px solid var(--clr-border);
  white-space: nowrap;
}
.data-table td {
  padding: .7rem 1rem;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #f9fafb; }
.data-table a { font-weight: 500; }

/* ----------------------------------------------------------------
   Badges
   ---------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
.badge-grand   { background: #ede9fe; color: #6d28d9; }
.badge-upright { background: #dbeafe; color: #1d4ed8; }
.badge-digital { background: #d1fae5; color: #065f46; }
.badge-other   { background: #f3f4f6; color: #374151; }

.badge-open        { background: #e5e7eb; color: #374151; }
.badge-in-progress { background: #dbeafe; color: #1d4ed8; }
.badge-complete    { background: #d1fae5; color: #065f46; }
.badge-cancelled   { background: #f3f4f6; color: #9ca3af; }

.badge-low    { background: #f3f4f6; color: #6b7280; }
.badge-normal { background: #e5e7eb; color: #374151; }
.badge-high   { background: #ffedd5; color: #c2410c; }
.badge-urgent { background: #fee2e2; color: #dc2626; }

.badge-overdue   { background: #fee2e2; color: #dc2626; }
.badge-due-soon  { background: #fef3c7; color: #b45309; }
.badge-upcoming  { background: #dbeafe; color: #1d4ed8; }

.badge-excellent  { background: #d1fae5; color: #065f46; }
.badge-good       { background: #dbeafe; color: #1d4ed8; }
.badge-fair       { background: #fef3c7; color: #b45309; }
.badge-poor       { background: #fee2e2; color: #dc2626; }
.badge-attention  { background: #dc2626; color: #fff; }

/* ----------------------------------------------------------------
   Buttons
   ---------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--clr-primary); color: #fff; }
.btn-primary:hover { background: var(--clr-primary-h); }
.btn-secondary { background: var(--clr-surface); color: var(--clr-text); border-color: var(--clr-border); }
.btn-secondary:hover { background: #f3f4f6; }
.btn-danger { background: var(--clr-danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--clr-success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-xs { padding: .2rem .5rem; font-size: .75rem; }

/* ----------------------------------------------------------------
   Forms
   ---------------------------------------------------------------- */
.form-group { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .85rem; }
.form-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--clr-text);
}
.form-input,
.form-select,
.form-textarea {
  padding: .5rem .7rem;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: inherit;
  background: var(--clr-surface);
  transition: border-color .15s;
  width: 100%;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-error { color: var(--clr-danger); font-size: .82rem; }

/* ----------------------------------------------------------------
   Modal overlay
   ---------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal-box {
  background: var(--clr-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { font-size: 1.05rem; font-weight: 600; margin: 0; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--clr-text-sec);
  line-height: 1;
}
.modal-body { padding: 1.25rem; }
.modal-footer {
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--clr-border);
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}

/* ----------------------------------------------------------------
   Empty state
   ---------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--clr-text-sec);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .75rem; opacity: .5; }
.empty-state p { font-size: .95rem; }

/* ----------------------------------------------------------------
   Messages / alerts
   ---------------------------------------------------------------- */
.alert {
  padding: .7rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  margin-bottom: 1rem;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ----------------------------------------------------------------
   Login page
   ---------------------------------------------------------------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--clr-bg);
  padding: 1rem;
}
.login-card {
  background: var(--clr-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
}
.login-card h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: .3rem;
  text-align: center;
}

.login-card .subtitle {
  text-align: center;
  color: var(--clr-text-sec);
  font-size: .9rem;
  margin-bottom: 1.5rem;
}
.login-card .btn-primary { width: 100%; justify-content: center; margin-top: .5rem; }

/* ----------------------------------------------------------------
   HTMX loading indicator
   ---------------------------------------------------------------- */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }

/* ----------------------------------------------------------------
   Utilities
   ---------------------------------------------------------------- */
.text-muted { color: var(--clr-text-sec); }
.text-dim { color: var(--clr-text-dim); }
.text-danger { color: var(--clr-danger); }
.text-success { color: var(--clr-success); }
.text-sm { font-size: .82rem; }
.fw-medium { font-weight: 500; }
.fw-bold { font-weight: 700; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-row { display: flex; gap: .5rem; align-items: center; }

/* ----------------------------------------------------------------
   Responsive — mobile
   ---------------------------------------------------------------- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; }
  .hamburger { display: block; }
  .page-content { padding: 1rem; }
  .form-row { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .page-header { flex-direction: column; align-items: flex-start; }
  .active-company-pill { max-width: 160px; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
