:root {
  --brand: #f47c01;
  --brand-dark: #d96b00;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e5e9f2;
  --text: #000000;
  --text-muted: #4b5563;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --sidebar-w: 240px;
  --topnav-h: 60px;
  --font-title: 20px;
  --font-body: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: var(--font-body);
}

h1, h2, h3, .card-title, .auth-title, .topnav-title { color: var(--text); }
p, td, th, label, .stat-sub, .field-input, .badge { font-size: var(--font-body); }

/* ---------- Logo ---------- */
.brand-logo-full { height: 36px; width: auto; display: block; }
.brand-logo-mark { height: 32px; width: auto; display: block; }

/* ---------- Auth page ---------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eef2ff 0%, #f4f6fb 100%);
}
.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 10px 40px rgba(20, 30, 60, 0.08);
}
.auth-title { margin: 0 0 4px; font-size: var(--font-title); font-weight: 700; color: var(--text); }
.auth-subtitle { margin: 0 0 24px; color: var(--text-muted); font-size: var(--font-body); }

.field-label { display: block; font-weight: 600; margin: 14px 0 6px; font-size: var(--font-body); }
.field-input, select.field-input, textarea.field-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: var(--font-body); background: #fff; color: var(--text);
}
.field-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(244,124,1,.15); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 8px; font-weight: 600; font-size: var(--font-body);
  border: 1px solid transparent; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; margin-top: 20px; }
.btn-sm { padding: 6px 12px; font-size: var(--font-body); }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: var(--font-body); }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

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

.sidebar {
  width: var(--sidebar-w); background: #ffffff; color: #000000;
  flex-shrink: 0; position: fixed; top: 0; bottom: 0; left: 0; overflow-y: auto;
  transition: transform .2s ease; z-index: 40; border-right: 1px solid var(--border);
}
.sidebar-brand {
  padding: 16px 20px; display: flex; align-items: center;
  border-bottom: 1px solid var(--border);
}
.sidebar-nav { padding: 10px; }
.sidebar-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; color: #000000; text-decoration: none; font-size: var(--font-body); margin-bottom: 2px;
  font-weight: 600;
}
.sidebar-link:hover { background: #fff3e6; }
.sidebar-link.active { background: var(--brand); color: #fff; }

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

.topnav {
  height: var(--topnav-h); background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 30;
}
.topnav-title { font-size: var(--font-title); font-weight: 700; color: var(--text); }
.topnav-user { display: flex; align-items: center; gap: 12px; font-size: var(--font-body); color: var(--text-muted); }
.topnav-user > * { flex-shrink: 0; }

.page-content { padding: 24px; }

/* ---------- Dashboard cards ---------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-label { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-value { font-size: var(--font-title); font-weight: 700; margin-top: 6px; color: var(--text); }
.stat-sub { font-size: var(--font-body); color: var(--text-muted); margin-top: 4px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: var(--font-title); font-weight: 700; margin: 0; }

table.data-table { width: 100%; border-collapse: collapse; font-size: var(--font-body); }
.data-table th {
  text-align: left; padding: 10px 12px; color: var(--text-muted); font-weight: 600;
  border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text); }
.data-table tr:hover td { background: #fff8f0; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #ffe8cc; color: #b35900; }
.badge-gray    { background: #f1f5f9; color: #000000; }

/* Long inline code/paths must never force the page to scroll horizontally */
code { overflow-wrap: anywhere; word-break: break-word; }

/* ---------- Responsive tables ---------- */
.table-responsive { width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; position: relative; }
.table-responsive table.data-table { min-width: 560px; }

/* ---------- Mobile menu toggle ---------- */
.sidebar-toggle-btn {
  display: none;
  background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer;
  padding: 4px 8px; color: var(--text); margin-right: 4px;
}
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 39;
}
.sidebar-backdrop.visible { display: block; }


/* ---------- World clock dropdown (top bar) ---------- */
.clock-dropdown { position: relative; display: inline-block; }
.clock-toggle { padding: 8px 10px; line-height: 1; }
.clock-icon {
  display: inline-block; font-size: 16px;
  animation: clock-tick 2s steps(1) infinite;
}
@keyframes clock-tick {
  0%   { transform: rotate(0deg); }
  25%  { transform: rotate(8deg); }
  50%  { transform: rotate(0deg); }
  75%  { transform: rotate(-8deg); }
  100% { transform: rotate(0deg); }
}
.clock-panel {
  display: none;
  position: absolute; right: 0; top: calc(100% + 8px);
  width: 260px; max-height: 360px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(20,30,60,.12);
  padding: 8px; z-index: 50;
}
.clock-dropdown.open .clock-panel { display: block; }
.clock-row {
  display: grid; grid-template-columns: 20px 1fr auto; grid-template-areas: "flag country time" ". tz tz";
  align-items: center; gap: 2px 8px; padding: 8px 6px; border-radius: 6px;
}
.clock-row:hover { background: #fff8f0; }
.clock-flag { grid-area: flag; font-size: 15px; }
.clock-country { grid-area: country; font-size: 12px; font-weight: 600; color: var(--text); }
.clock-time { grid-area: time; font-size: 12px; font-weight: 700; color: var(--brand); font-variant-numeric: tabular-nums; }
.clock-tz { grid-area: tz; font-size: 10px; color: var(--text-muted); }

/* Responsive */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); z-index: 45; box-shadow: 0 0 30px rgba(0,0,0,.15); }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; }
  .sidebar-toggle-btn { display: inline-flex; align-items: center; }
}

@media (max-width: 640px) {
  .topnav { padding: 0 10px; }
  .topnav-title { font-size: 16px; }
  .topnav-user { gap: 6px; }
  .topnav-user > a[href="/profile.php"] {
    max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .page-content { padding: 12px; }
  .card { padding: 14px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-value { font-size: 20px; }
  .card-header { flex-wrap: wrap; gap: 8px; }
  .auth-card { padding: 24px; margin: 16px; }
  .btn { padding: 8px 12px; }
  .btn-sm { padding: 6px 10px; }

  /* The clock panel is anchored to the viewport edges here instead of to the
     toggle button — on a narrow screen the button sits close to the right
     edge, so a fixed-width panel anchored to the *button* would spill off
     the left side of the screen. Anchoring to the viewport avoids that
     regardless of where the button ends up. */
  .clock-panel {
    position: fixed;
    top: calc(var(--topnav-h) + 8px);
    left: 12px;
    right: 12px;
    width: auto;
    max-height: 65vh;
  }

  /* This box-shadow scroll hint is now unused (tables convert to stacked
     cards below 700px instead of scrolling), left harmless for anything
     between 641-700px that still uses horizontal scroll as a fallback. */
  .table-responsive { box-shadow: inset -14px 0 10px -12px rgba(0,0,0,.12); }
  .table-responsive.scrolled-end { box-shadow: none; }
}

@media (max-width: 420px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .sidebar-brand img { height: 26px; }
}

/* ---------- Mobile tables: stacked cards instead of horizontal scroll ----------
   Below 700px, a wide table with many columns is genuinely hard to use even
   with horizontal scrolling — nothing indicates it's scrollable, and content
   getting cut off at the card edge looks broken. Below this breakpoint every
   .data-table instead renders each row as its own small card, with column
   headers shown as inline labels via the td's data-label attribute. */
@media (max-width: 700px) {
  .table-responsive { overflow-x: visible; box-shadow: none; }
  .table-responsive table.data-table { min-width: 0; }
  table.data-table { width: 100%; }
  table.data-table thead { display: none; }
  table.data-table, table.data-table tbody, table.data-table tr, table.data-table td {
    display: block; width: 100%;
  }
  table.data-table tr {
    border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px;
    padding: 4px 12px; background: var(--surface);
  }
  table.data-table tr:hover td { background: transparent; }
  table.data-table td {
    display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap;
    padding: 8px 0; border-bottom: 1px solid #f1f5f9; text-align: right;
  }
  table.data-table td:last-child { border-bottom: none; }
  table.data-table td:empty { display: none; }
  table.data-table td::before {
    content: attr(data-label);
    font-weight: 600; color: var(--text-muted); text-align: left;
    flex-shrink: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .02em;
  }
  table.data-table td[data-label=""]::before,
  table.data-table td:not([data-label])::before { content: none; }
  /* A cell holding only a checkbox, a link, or buttons should still show its
     label but let the control sit naturally rather than being squeezed right */
  table.data-table td form { margin: 0; }
  table.data-table td:has(input[type="checkbox"]) { justify-content: flex-start; }
}
