/* =========================================================================
   MADARA GROUP — Design tokens
   Palette: deep navy (#0F1B3D) / warm gold (#B8892B) / cream (#F4F1EA)
   ========================================================================= */
:root {
  --navy-950: #0a1229;
  --navy-900: #0F1B3D;
  --navy-800: #16255a;
  --navy-700: #1f3374;
  --gold-600: #a9791f;
  --gold-500: #B8892B;
  --gold-400: #d1a54a;
  --gold-100: #F4E7C6;
  --cream: #F7F5EF;
  --ink: #1a1a2e;
  --ink-soft: #4b4f63;
  --line: #e4e1d8;
  --white: #ffffff;
  --success: #1e8a5f;
  --danger: #c0392b;
  --warn: #b8860b;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 27, 61, 0.06);
  --shadow-md: 0 6px 20px rgba(15, 27, 61, 0.10);
  --sidebar-w: 248px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--cream);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 800; letter-spacing: -0.01em; color: var(--navy-900); }
p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
a { color: var(--navy-800); }
::selection { background: var(--gold-100); }

/* =========================================================================
   Login screen
   ========================================================================= */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(184,137,43,0.20), transparent),
    radial-gradient(900px 500px at 110% 110%, rgba(184,137,43,0.12), transparent),
    linear-gradient(160deg, var(--navy-950), var(--navy-900) 55%, var(--navy-800));
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  padding: 36px 32px 28px;
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 22px; text-align: center; }
.login-brand__name { font-size: 20px; font-weight: 800; color: var(--navy-900); letter-spacing: 0.4px; }
.login-brand__tag { font-size: 12.5px; color: var(--ink-soft); }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-tabs { display: flex; background: var(--cream); border-radius: 999px; padding: 4px; margin-bottom: 4px; }
.login-tab {
  flex: 1; text-align: center; padding: 8px 10px; border: none; background: transparent;
  border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--ink-soft);
}
.login-tab.active { background: var(--navy-900); color: var(--gold-100); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  border: 1.5px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
  font-size: 14px; color: var(--ink); background: var(--white); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--gold-500); box-shadow: 0 0 0 3px rgba(184,137,43,0.18);
}
.field-error { color: var(--danger); font-size: 12px; }
.login-error { background: #fdecea; color: var(--danger); border-radius: var(--radius); padding: 10px 12px; font-size: 13px; }
.login-help { margin-top: 18px; font-size: 12px; color: var(--ink-soft); background: var(--cream); border-radius: var(--radius); padding: 12px 14px; line-height: 1.6; }
.login-help b { color: var(--navy-900); }

/* =========================================================================
   App shell
   ========================================================================= */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--navy-900); color: var(--gold-100);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 40;
}
.sidebar__brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar__brand-text { line-height: 1.15; }
.sidebar__brand-name { font-size: 14.5px; font-weight: 800; color: #fff; letter-spacing: 0.3px; }
.sidebar__brand-sub { font-size: 10.5px; color: var(--gold-400); }
.sidebar__nav { flex: 1; overflow-y: auto; padding: 10px 10px 16px; }
.sidebar__section-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: rgba(244,231,198,0.45); padding: 14px 10px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: rgba(244,231,198,0.85); text-decoration: none; font-size: 13.5px; font-weight: 600; margin-bottom: 2px;
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: var(--gold-500); color: var(--navy-950); }
.nav-link__icon { width: 18px; text-align: center; flex-shrink: 0; }
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 800; border-radius: 999px; padding: 1px 6px; }
.sidebar__footer { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar__user { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin-bottom: 8px; }
.avatar-dot { width: 28px; height: 28px; border-radius: 50%; background: var(--gold-500); color: var(--navy-950); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12px; flex-shrink: 0; }

.main {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
}
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 22px; background: var(--white);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30;
}
.topbar__menu-btn { display: none; background: none; border: none; font-size: 20px; color: var(--navy-900); padding: 4px 8px; }
.topbar__search { flex: 1; max-width: 460px; position: relative; }
.topbar__search input {
  width: 100%; padding: 9px 14px 9px 34px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--cream); font-size: 13.5px;
}
.topbar__search input:focus { outline: none; border-color: var(--gold-500); background: #fff; }
.topbar__search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); font-size: 13px; }
.topbar__spacer { flex: 1; }
.icon-btn {
  background: var(--cream); border: none; border-radius: 999px; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center; position: relative; font-size: 15px; color: var(--navy-900);
}
.icon-btn .nav-badge { position: absolute; top: -3px; right: -3px; }

.content { padding: 20px 22px 60px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
  border: none; border-radius: var(--radius); padding: 9px 16px; font-size: 13.5px; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px; transition: transform 0.05s ease;
}
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--navy-900); color: #fff; }
.btn--primary:hover { background: var(--navy-800); }
.btn--gold { background: var(--gold-500); color: var(--navy-950); }
.btn--gold:hover { background: var(--gold-400); }
.btn--ghost { background: var(--cream); color: var(--navy-900); }
.btn--ghost:hover { background: #ece7d8; }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: #a5301f; }
.btn--sm { padding: 6px 11px; font-size: 12.5px; }
.btn--block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: 0.55; pointer-events: none; }

/* =========================================================================
   Cards / dashboard
   ========================================================================= */
.page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-header h1 { font-size: 21px; }
.page-header__sub { color: var(--ink-soft); font-size: 13px; }
.page-header__actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--white); border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow-sm); border: 1px solid var(--line); }
.stat-card__label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); font-weight: 700; }
.stat-card__value { font-size: 24px; font-weight: 800; color: var(--navy-900); margin-top: 6px; }
.stat-card__value.gold { color: var(--gold-600); }
.stat-card--accent { border-left: 4px solid var(--gold-500); }

.panel { background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); border: 1px solid var(--line); padding: 18px; margin-bottom: 18px; }
.panel__title { font-size: 14.5px; font-weight: 800; color: var(--navy-900); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.panel-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
@media (max-width: 980px) { .panel-grid { grid-template-columns: 1fr; } }

.chart-bars { display: flex; align-items: flex-end; gap: 10px; height: 140px; padding-top: 10px; }
.chart-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.chart-bar { width: 100%; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, var(--gold-400), var(--gold-600)); min-height: 3px; }
.chart-bar.alt { background: linear-gradient(180deg, var(--navy-700), var(--navy-900)); }
.chart-bar-label { font-size: 10.5px; color: var(--ink-soft); }
.legend { display: flex; gap: 14px; font-size: 11.5px; color: var(--ink-soft); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

.donut-wrap { display: flex; align-items: center; gap: 16px; }
.progress-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 12.5px; }
.progress-row__label { width: 110px; flex-shrink: 0; color: var(--ink-soft); }
.progress-track { flex: 1; height: 8px; background: var(--cream); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--gold-500); }
.progress-row__val { width: 34px; text-align: right; font-weight: 700; color: var(--navy-900); }

.activity-list { display: flex; flex-direction: column; gap: 0; }
.activity-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold-500); margin-top: 5px; flex-shrink: 0; }
.activity-item__meta { color: var(--ink-soft); font-size: 11px; margin-top: 2px; }

/* =========================================================================
   Tables
   ========================================================================= */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--line); background: #fff; }
table.data-table { width: 100%; border-collapse: collapse; min-width: 640px; }
.data-table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); background: var(--cream); padding: 10px 14px; white-space: nowrap; }
.data-table td { padding: 11px 14px; font-size: 13px; border-top: 1px solid var(--line); vertical-align: middle; }
.data-table tr:hover td { background: #fbfaf6; }
.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.link-name { color: var(--navy-900); font-weight: 700; text-decoration: none; }
.link-name:hover { text-decoration: underline; }
.subtext { color: var(--ink-soft); font-size: 11.5px; }

.table-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.table-toolbar__search { flex: 1; min-width: 200px; }
.select-filter { border: 1.5px solid var(--line); border-radius: var(--radius); padding: 8px 10px; font-size: 13px; background: #fff; }
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; font-size: 12.5px; color: var(--ink-soft); }
.pagination__btns { display: flex; gap: 6px; }

/* badges */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; letter-spacing: 0.02em; }
.badge--active, .badge--completed, .badge--available { background: #e5f4ee; color: var(--success); }
.badge--pending, .badge--new, .badge--waiting { background: #fdf3dc; color: var(--warn); }
.badge--inprogress, .badge--assigned { background: #e6ecfb; color: #2b4fbf; }
.badge--cancelled, .badge--terminated, .badge--lost, .badge--damaged { background: #fdecea; color: var(--danger); }
.badge--suspended, .badge--underrepair, .badge--returned, .badge--retired { background: #eee; color: #555; }

/* =========================================================================
   Forms / modals
   ========================================================================= */
.modal-root { position: fixed; inset: 0; z-index: 100; display: none; }
.modal-root--open { display: block; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,18,41,0.55); display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 30px 14px; }
.modal { background: #fff; border-radius: var(--radius-lg); width: 100%; max-width: 640px; padding: 22px 24px 24px; box-shadow: var(--shadow-md); }
.modal--sm { max-width: 400px; }
.modal--lg { max-width: 880px; }
.modal__title { font-size: 17px; margin-bottom: 4px; }
.modal__subtitle { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 16px; }
.modal__body { color: var(--ink-soft); font-size: 13.5px; margin: 10px 0 4px; }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.modal__close { position: absolute; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 620px) { .form-grid { grid-template-columns: 1fr; } }

/* =========================================================================
   Toasts
   ========================================================================= */
#toast-host { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
.toast {
  background: var(--navy-900); color: #fff; padding: 11px 14px; border-radius: var(--radius); font-size: 13px;
  display: flex; align-items: center; gap: 9px; box-shadow: var(--shadow-md); opacity: 0; transform: translateX(20px); transition: all 0.25s ease;
}
.toast--in { opacity: 1; transform: translateX(0); }
.toast__icon { width: 18px; height: 18px; border-radius: 50%; background: rgba(255,255,255,0.18); display: flex; align-items: center; justify-content: center; font-size: 11px; flex-shrink: 0; }
.toast--success .toast__icon { background: var(--success); }
.toast--error .toast__icon { background: var(--danger); }
.toast--warn .toast__icon { background: var(--warn); }

/* =========================================================================
   Empty / loading states
   ========================================================================= */
.empty-state { text-align: center; padding: 46px 20px; color: var(--ink-soft); }
.empty-state__icon { font-size: 32px; margin-bottom: 10px; }
.empty-state__title { font-weight: 800; color: var(--navy-900); margin-bottom: 4px; }
.skeleton { background: linear-gradient(90deg, #eee 25%, #f5f5f5 37%, #eee 63%); background-size: 400% 100%; animation: skeleton-loading 1.4s ease infinite; border-radius: 6px; }
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skeleton-row { height: 16px; margin: 10px 14px; }

/* =========================================================================
   Search results / profile
   ========================================================================= */
.search-result-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow-sm); }
.search-result-card h3 { font-size: 15px; margin-bottom: 10px; }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px 16px; font-size: 12.5px; }
.kv-grid dt { color: var(--ink-soft); font-weight: 600; }
.kv-grid dd { margin: 0; color: var(--ink); font-weight: 600; }

.profile-header { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.profile-avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--navy-900); color: var(--gold-100); display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 800; flex-shrink: 0; }
.profile-header__name { font-size: 19px; }
.profile-header__meta { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab-btn { padding: 9px 14px; font-size: 13px; font-weight: 700; color: var(--ink-soft); background: none; border: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab-btn.active { color: var(--navy-900); border-color: var(--gold-500); }

/* =========================================================================
   Utility
   ========================================================================= */
.hidden { display: none !important; }
.text-muted { color: var(--ink-soft); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 20px; }
.mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; }
.flex { display: flex; } .items-center { align-items: center; } .gap-2 { gap: 8px; }
.w-full { width: 100%; }

/* =========================================================================
   Mobile responsiveness
   ========================================================================= */
.sidebar-scrim { display: none; }
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform 0.22s ease; box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 39; }
  .topbar__menu-btn { display: inline-flex; }
  .content { padding: 16px 14px 50px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar__search { max-width: none; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { max-width: 96vw; padding: 18px; }
}
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 12px 14px; }
  .stat-card__value { font-size: 19px; }
  .page-header h1 { font-size: 18px; }
  .table-wrap { border-radius: var(--radius); }
}

/* Card-based responsive table (used on very small screens for long tables) */
@media (max-width: 700px) {
  .cards-on-mobile table.data-table thead { display: none; }
  .cards-on-mobile table.data-table { min-width: 0; }
  .cards-on-mobile table.data-table, .cards-on-mobile table.data-table tbody, .cards-on-mobile table.data-table tr, .cards-on-mobile table.data-table td { display: block; width: 100%; }
  .cards-on-mobile table.data-table tr { border-bottom: 1px solid var(--line); padding: 10px 14px; }
  .cards-on-mobile table.data-table td { border: none; padding: 4px 0; display: flex; justify-content: space-between; gap: 10px; }
  .cards-on-mobile table.data-table td::before { content: attr(data-label); font-weight: 700; color: var(--ink-soft); font-size: 11.5px; }
  .cards-on-mobile table.data-table td.row-actions::before { content: ''; }
}

/* Print: hide app chrome when printing the SPA itself (fallback) */
@media print {
  .sidebar, .topbar, .page-header__actions, .row-actions, #toast-host { display: none !important; }
}
