/* =========================================================
   SIMPRO Design System
   One shared visual language for every page: sidebar, topnav,
   cards, tables, forms, buttons, badges, modals, alerts,
   pagination, empty/loading/error states. Responsive:
   desktop / tablet / mobile.
   ========================================================= */

:root {
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-success: #16a34a;
  --color-danger: #dc2626;
  --color-warning: #d97706;
  --color-info: #0891b2;
  --color-bg: #f4f6fb;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --sidebar-width: 250px;
  --topnav-height: 60px;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
  width: var(--sidebar-width);
  background: #111827;
  color: #cbd5e1;
  flex-shrink: 0;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
  z-index: 40;
  transition: transform .2s ease;
}
.sidebar-brand {
  padding: 18px 20px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand small { display:block; font-weight:400; font-size:11px; color:#94a3b8; }
.sidebar nav { padding: 10px 0; }
.sidebar .nav-section { padding: 10px 20px 4px; font-size: 11px; text-transform: uppercase; color: #64748b; letter-spacing: .05em; }
.sidebar a.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: #cbd5e1; font-size: 13.5px;
}
.sidebar a.nav-link:hover, .sidebar a.nav-link.active {
  background: rgba(255,255,255,.06); color: #fff; text-decoration: none;
}

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

.topnav {
  height: var(--topnav-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 30;
}
.topnav .menu-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; }
.topnav .user-menu { display: flex; align-items: center; gap: 12px; }
.topnav .user-menu .role-badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #eef2ff; color: var(--color-primary-dark); }

.content { padding: 22px; flex: 1; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { font-size: 20px; margin: 0; }
.page-header .breadcrumb { font-size: 12px; color: var(--color-text-muted); }

/* ---------- Cards / stat tiles ---------- */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-body { padding: 18px; }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--color-border); font-weight: 600; display:flex; align-items:center; justify-content:space-between; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-tile { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.stat-tile .label { font-size: 12px; color: var(--color-text-muted); }
.stat-tile .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat-tile.warn .value { color: var(--color-warning); }
.stat-tile.danger .value { color: var(--color-danger); }
.stat-tile.success .value { color: var(--color-success); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 6px; border: 1px solid transparent;
  font-size: 13.5px; font-weight: 500; cursor: pointer; line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: #fff; color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-success { background: var(--color-success); color: #fff; }
.btn-warning { background: #f59e0b; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.form-label .req { color: var(--color-danger); }
.form-control {
  width: 100%; padding: 8px 10px; border: 1px solid var(--color-border);
  border-radius: 6px; font-size: 13.5px; background: #fff; color: var(--color-text);
}
.form-control:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-help { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--color-danger); margin-top: 4px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; background: var(--color-surface); }
table.table th, table.table td { padding: 10px 14px; border-bottom: 1px solid var(--color-border); text-align: left; font-size: 13px; white-space: nowrap; }
table.table th { background: #f8fafc; font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; font-size: 11px; letter-spacing: .03em; }
table.table tbody tr:hover { background: #f8fafc; }
table.table td.wrap { white-space: normal; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-muted { background: #f1f5f9; color: #475569; }

/* ---------- Alerts / flash ---------- */
.alert { padding: 12px 16px; border-radius: 6px; font-size: 13.5px; margin-bottom: 16px; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ---------- Filters / toolbar ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 4px; margin-top: 14px; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 6px 11px; border: 1px solid var(--color-border); border-radius: 6px; font-size: 12.5px; color: var(--color-text); }
.pagination a:hover { background: #f8fafc; text-decoration: none; }
.pagination .active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ---------- Empty / loading / error states ---------- */
.state-box { text-align: center; padding: 50px 20px; color: var(--color-text-muted); }
.state-box .icon { font-size: 34px; margin-bottom: 10px; }
.loading-inline { display: inline-flex; align-items: center; gap: 8px; color: var(--color-text-muted); font-size: 13px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--color-border); border-top-color: var(--color-primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-backdrop.open { display: flex; }
.modal-box { background: #fff; border-radius: var(--radius); width: 100%; max-width: 440px; box-shadow: var(--shadow-md); }
.modal-header { padding: 16px 18px; border-bottom: 1px solid var(--color-border); font-weight: 600; }
.modal-body { padding: 18px; font-size: 13.5px; }
.modal-footer { padding: 14px 18px; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; }
  .topnav .menu-toggle { display: inline-block; }
  .stat-grid { grid-template-columns: 1fr; }
}

/* ---------- Print ---------- */
@media print {
  .sidebar, .topnav, .toolbar, .no-print { display: none !important; }
  .main-area { margin-left: 0 !important; }
  body { background: #fff; }
}
