/* =========================================================
   Casino Installation Manager — Design System
   Modern SaaS admin dashboard. Light & dark mode via [data-theme]
   ========================================================= */

:root {
  --brand-50: #eef2ff;
  --brand-100: #e0e7ff;
  --brand-200: #c7d2fe;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;

  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #0ea5e9;

  --sidebar-w: 264px;
  --topbar-h: 64px;
  --radius: 14px;

  /* Light theme (default) */
  --bg: #f3f5fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e9f2;
  --text: #1e293b;
  --text-muted: #64748b;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-md: 0 6px 24px rgba(15, 23, 42, .08);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, .14);
  --sidebar-bg: #111827;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #64748b;
  --sidebar-active: #4f46e5;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #141c2e;
  --surface-2: #1a2338;
  --border: #26324a;
  --text: #e2e8f0;
  --text-muted: #8fa3bf;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 8px 26px rgba(0, 0, 0, .45);
  --shadow-lg: 0 14px 44px rgba(0, 0, 0, .55);
  --sidebar-bg: #0b1220;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #5b6b83;
  --sidebar-active: #6366f1;
}

/* ---------- Bootstrap overrides ---------- */
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

[data-bs-theme="dark"] body {
  color: var(--text);
}

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
  color: var(--text);
}

a { color: var(--brand-600); text-decoration: none; }
[data-theme="dark"] a { color: #a5b4fc; }
a:hover { text-decoration: underline; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.table {
  --bs-table-bg: transparent;
  color: var(--text);
}

.form-control, .form-select {
  background-color: var(--surface);
  color: var(--text);
  border-color: var(--border);
  border-radius: 10px;
  padding: .55rem .85rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 .2rem rgba(99, 102, 241, .18);
  background-color: var(--surface);
  color: var(--text);
}
.form-control::placeholder { color: var(--text-muted); opacity: .75; }

.form-label { font-weight: 600; font-size: .85rem; color: var(--text); }
.form-text, .text-muted, small, .form-label .optional { color: var(--text-muted); }

.btn { border-radius: 10px; font-weight: 600; }
.btn-primary { background: var(--brand-600); border-color: var(--brand-600); }
.btn-primary:hover { background: var(--brand-700); border-color: var(--brand-700); }
.btn-outline-primary { color: var(--brand-600); border-color: var(--brand-600); }
.btn-light { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-outline-secondary { color: var(--text-muted); border-color: var(--border); }
.btn-icon { padding: .35rem .55rem; border-radius: 9px; }

.dropdown-menu {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
}
.dropdown-item { color: var(--text); border-radius: 8px; }
.dropdown-item:hover { background: var(--brand-50); color: var(--text); }
[data-theme="dark"] .dropdown-item:hover { background: #22304a; }
.dropdown-item i { width: 1.1rem; color: var(--text-muted); }

.modal-content { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; }
.modal-header, .modal-footer { border-color: var(--border); }

.pagination { gap: .25rem; }
.page-link {
  background: var(--surface); color: var(--text); border-color: var(--border);
  border-radius: 8px !important; margin: 0 .1rem; min-width: 34px; text-align: center;
}
.page-item.active .page-link { background: var(--brand-600); border-color: var(--brand-600); }
.page-item.disabled .page-link { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }

/* =========================================================
   Layout
   ========================================================= */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease, width .25s ease;
}

.sidebar .brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: 0 1.15rem;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff; font-size: 1.1rem; flex: 0 0 36px;
}
.brand-name { font-weight: 700; font-size: .98rem; letter-spacing: -.01em; white-space: nowrap; }

.sidebar .nav-scroll { flex: 1; overflow-y: auto; padding: .85rem .7rem; }
.sidebar .nav-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--sidebar-muted); padding: .9rem .6rem .35rem;
}

.sidebar .nav-item { margin-bottom: .12rem; }
.sidebar .nav-link {
  color: var(--sidebar-text);
  border-radius: 10px;
  display: flex; align-items: center; gap: .7rem;
  padding: .62rem .7rem;
  font-weight: 500; font-size: .9rem;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.sidebar .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; color: var(--sidebar-muted); transition: color .15s; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar .nav-link:hover i { color: #fff; }
.sidebar .nav-link.active { background: linear-gradient(135deg, rgba(99,102,241,.25), rgba(139,92,246,.18)); color: #fff; }
.sidebar .nav-link.active i { color: #c7d2fe; }
.sidebar .nav-link .badge-float { margin-left: auto; }

.sidebar-footer {
  padding: .8rem 1rem;
  border-top: 1px solid rgba(255,255,255,.06);
  font-size: .72rem; color: var(--sidebar-muted);
  display: flex; align-items: center; gap: .5rem;
}

.main-area {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left .25s ease;
}

.topbar {
  height: var(--topbar-h);
  position: sticky; top: 0;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1.4rem;
  z-index: 1030;
}
.topbar .btn-icon {
  background: transparent; border: none; color: var(--text-muted);
  width: 40px; height: 40px; border-radius: 10px;
}
.topbar .btn-icon:hover { background: var(--surface-2); color: var(--text); }

.content { padding: 1.5rem 1.6rem 3rem; flex: 1; }

/* Collapsed sidebar */
.app-shell.sidebar-collapsed .sidebar { transform: translateX(-100%); }
.app-shell.sidebar-collapsed .main-area { margin-left: 0; }

/* Mobile overlay */
.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  z-index: 1039; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.app-shell.mobile-menu-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
.app-shell.mobile-menu-open .sidebar-overlay { opacity: 1; pointer-events: auto; }

.sidebar-backdrop-close { display: none; }

/* =========================================================
   Page header / breadcrumbs
   ========================================================= */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.35rem; }
.page-head h1 { font-size: 1.45rem; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.breadcrumb { margin: 0; font-size: .82rem; }
.breadcrumb-item a { color: var(--text-muted); }
.breadcrumb-item.active { color: var(--text-muted); }
.breadcrumb-item::before { color: var(--text-muted) !important; }

/* =========================================================
   Stat cards
   ========================================================= */
.stat-card {
  display: flex; align-items: center; gap: 1rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-sm);
  height: 100%;
}
.stat-card .icon {
  width: 50px; height: 50px; border-radius: 14px; flex: 0 0 50px;
  display: grid; place-items: center; font-size: 1.4rem;
}
.stat-card .value { font-size: 1.55rem; font-weight: 800; line-height: 1.1; color: var(--text); }
.stat-card .label { color: var(--text-muted); font-size: .82rem; font-weight: 500; }

.grad-indigo { background: linear-gradient(135deg, #eef2ff, #e0e7ff); color: var(--brand-600); }
.grad-sky { background: linear-gradient(135deg, #e0f2fe, #bae6fd); color: #0284c7; }
.grad-emerald { background: linear-gradient(135deg, #d1fae5, #a7f3d0); color: #059669; }
.grad-amber { background: linear-gradient(135deg, #fef3c7, #fde68a); color: #d97706; }
.grad-rose { background: linear-gradient(135deg, #ffe4e6, #fecdd3); color: #e11d48; }
.grad-violet { background: linear-gradient(135deg, #ede9fe, #ddd6fe); color: #7c3aed; }
[data-theme="dark"] .grad-indigo { background: rgba(99,102,241,.2); color: #a5b4fc; }
[data-theme="dark"] .grad-sky { background: rgba(14,165,233,.18); color: #7dd3fc; }
[data-theme="dark"] .grad-emerald { background: rgba(16,185,129,.18); color: #6ee7b7; }
[data-theme="dark"] .grad-amber { background: rgba(245,158,11,.16); color: #fcd34d; }
[data-theme="dark"] .grad-rose { background: rgba(244,63,94,.16); color: #fda4af; }
[data-theme="dark"] .grad-violet { background: rgba(139,92,246,.18); color: #c4b5fd; }

/* =========================================================
   Badges
   ========================================================= */
.badge-soft { font-weight: 600; padding: .4em .7em; border-radius: 999px; font-size: .72rem; }
.badge-active { background: #d1fae5; color: #047857; }
.badge-inactive { background: #fee2e2; color: #b91c1c; }
.badge-admin { background: #ede9fe; color: #6d28d9; }
.badge-user { background: #dbeafe; color: #1d4ed8; }
.badge-kind { background: #eef2ff; color: var(--brand-600); }
[data-theme="dark"] .badge-active { background: rgba(16,185,129,.18); color: #6ee7b7; }
[data-theme="dark"] .badge-inactive { background: rgba(239,68,68,.16); color: #fda4af; }
[data-theme="dark"] .badge-admin { background: rgba(139,92,246,.18); color: #c4b5fd; }
[data-theme="dark"] .badge-user { background: rgba(59,130,246,.18); color: #93c5fd; }
[data-theme="dark"] .badge-kind { background: rgba(99,102,241,.18); color: #a5b4fc; }

/* =========================================================
   Tables
   ========================================================= */
.data-table { margin: 0; vertical-align: middle; }
.data-table thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  font-weight: 700; border-bottom: 1px solid var(--border);
  padding: .8rem .9rem; white-space: nowrap;
}
.data-table tbody td { padding: .85rem .9rem; border-color: var(--border); }
.data-table tbody tr { transition: background .12s; }
.data-table tbody tr:hover { background: var(--surface-2); }

.record-no { font-weight: 800; color: var(--text); }
.record-sub { color: var(--text-muted); font-size: .8rem; }

.machine-cell { min-width: 230px; }
.machine-line { font-size: .86rem; color: var(--text); }
.machine-qty { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 20px; padding: 0 6px; font-weight: 700; border-radius: 6px; background: var(--brand-50); color: var(--brand-600); font-size: .75rem; }
[data-theme="dark"] .machine-qty { background: rgba(99,102,241,.2); color: #a5b4fc; }

.file-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; word-break: break-all; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); padding: .25rem .5rem; border-radius: 7px; display: inline-block; }

.actions-cell { white-space: nowrap; }
.actions-cell .btn { margin-right: .2rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: .25rem; }

/* Mobile record cards */
.mobile-cards { display: none; }
@media (max-width: 991.98px) {
  .desktop-table-wrap { display: none; }
  .mobile-cards { display: block; }
}

.mobile-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem; margin-bottom: .9rem;
}
.mobile-card .mc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; }
.mobile-card .mc-title { font-weight: 800; font-size: 1.05rem; }
.mobile-card .mc-sub { color: var(--text-muted); font-size: .85rem; }
.mobile-card .mc-label { color: var(--text-muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; margin-top: .65rem; }
.mobile-card .mc-value { font-size: .9rem; word-break: break-word; }

/* =========================================================
   Forms / machine builder
   ========================================================= */
.machine-builder { border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface-2); padding: 1rem; }
.machine-row { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .8rem .9rem; margin-bottom: .7rem; }
.machine-row .g-3, .machine-row .row { align-items: flex-end; }

.invalid-feedback { display: block; }

.form-section-title { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: 1.2rem 0 .7rem; }

/* =========================================================
   Timeline (history)
   ========================================================= */
.timeline { position: relative; padding-left: 1.7rem; }
.timeline::before {
  content: ""; position: absolute; left: 8px; top: 6px; bottom: 6px;
  width: 2px; background: var(--border); border-radius: 2px;
}
.timeline-item { position: relative; padding-bottom: 1.4rem; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
  position: absolute; left: -1.7rem; top: 4px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--brand-500);
}
.timeline-item.entry-deleted .timeline-dot { border-color: var(--danger); }
.timeline-item.entry-created .timeline-dot { border-color: var(--success); }
.timeline-meta { font-size: .78rem; color: var(--text-muted); margin-bottom: .3rem; }
.timeline-title { font-weight: 700; font-size: .92rem; margin-bottom: .4rem; }

.change-list { margin: 0; padding: 0; list-style: none; }
.change-list li { display: flex; gap: .5rem; padding: .28rem 0; font-size: .86rem; }
.change-list li i { color: var(--text-muted); margin-top: .18rem; }
.diff-old { text-decoration: line-through; color: var(--danger); }
.diff-new { color: var(--success); font-weight: 600; }

/* =========================================================
   Alerts / misc
   ========================================================= */
.alert { border-radius: 12px; border: none; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-danger { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-info { background: #e0f2fe; color: #0c4a6e; }
[data-theme="dark"] .alert-success { background: rgba(16,185,129,.16); color: #6ee7b7; }
[data-theme="dark"] .alert-danger { background: rgba(239,68,68,.16); color: #fca5a5; }
[data-theme="dark"] .alert-warning { background: rgba(245,158,11,.14); color: #fcd34d; }
[data-theme="dark"] .alert-info { background: rgba(14,165,233,.16); color: #7dd3fc; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state .icon { font-size: 2.6rem; opacity: .5; }

.quick-actions a { display: inline-flex; align-items: center; gap: .5rem; }
.mini-form { display: inline; }
.form-check-input:checked { background-color: var(--brand-600); border-color: var(--brand-600); }
input[type="checkbox"] { accent-color: var(--brand-600); }
input[type="date"]::-webkit-calendar-picker-indicator { cursor: pointer; }

textarea.form-control, input.form-control, select.form-select { font-size: .92rem; }

/* Scrollbar */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* =========================================================
   Auth / login
   ========================================================= */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: radial-gradient(1200px 600px at 10% -10%, rgba(99,102,241,.18), transparent), radial-gradient(900px 500px at 110% 110%, rgba(139,92,246,.15), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 440px; }
.auth-logo { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; font-size: 1.6rem; margin: 0 auto 1rem; box-shadow: 0 10px 24px rgba(99,102,241,.35); }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 767.98px) {
  .sidebar { transform: translateX(-100%); width: min(85vw, 300px); }
  .main-area { margin-left: 0 !important; }
  .content { padding: 1.1rem .95rem 2.5rem; }
  .page-head h1 { font-size: 1.2rem; }
  .stat-card { padding: .9rem 1rem; }
  .topbar { padding: 0 .7rem; }
}

/* Print */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main-area { margin-left: 0 !important; }
  .content { padding: 0; }
  body { background: #fff !important; }
}
