/* Aerial Solutions brand theme
   Palette from aerial-solutions.com: deep navy #16163F / #1B2C5D,
   brand red #ED1C24, link blue derived from site accent #2F8EF0.
   Fonts are air-gap safe Windows stand-ins: Bahnschrift ~ Rajdhani
   (headings), Segoe UI ~ Muli (body). No external assets. */
:root {
  --brand-navy: #16163f;
  --brand-navy-2: #1b2c5d;
  --brand-red: #ed1c24;
  --sidebar-bg: #16163f;
  --sidebar-active: #1b2c5d;
  --accent: #1b2c5d;
  --accent-light: #2f8ef0;
  --link: #1c6fd1;
  --bg: #f5f6f9;
  --card: #ffffff;
  --text: #22243a;
  --muted: #6b7186;
  --border: #dfe2ec;
  --danger: #b3362b;
  --warn: #b07d1e;
  --ok: #2e7d4f;
  --radius: 8px;
  --font-head: "Bahnschrift", "Segoe UI Semibold", "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  --font-body: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--font-head); color: var(--brand-navy); }

.layout { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 224px; flex-shrink: 0;
  background: var(--sidebar-bg); color: #c9cede;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
  background: #fff; padding: 16px 18px;
  border-bottom: 3px solid var(--brand-red);
}
.brand img { display: block; width: 100%; height: auto; }
.app-title {
  padding: 18px 16px 4px;
  font-family: var(--font-head); font-size: 20px; font-weight: 700;
  letter-spacing: 3px; text-transform: uppercase; color: #fff;
}
.app-title span { color: var(--brand-red); }
.nav-section {
  margin-top: 16px; padding: 0 16px;
  font-family: var(--font-head); font-size: 10px;
  text-transform: uppercase; letter-spacing: 1.4px; color: #7d84a3;
}
.sidebar a.nav-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px; color: #c9cede; font-size: 13.5px;
  border-left: 3px solid transparent;
}
.sidebar a.nav-item:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar a.nav-item.active {
  background: var(--sidebar-active); color: #fff;
  border-left-color: var(--brand-red);
}
.badge-alert {
  background: var(--brand-red); color: #fff; border-radius: 10px;
  font-size: 11px; padding: 1px 7px; font-weight: 600;
}
.sidebar .spacer { flex: 1; }
.lang-switch { display: flex; gap: 6px; padding: 10px 16px 0; }
.lang-switch button {
  font: inherit; font-size: 11.5px; cursor: pointer;
  padding: 3px 9px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.25); background: transparent; color: #c9cede;
}
.lang-switch button:hover { border-color: #fff; color: #fff; }
.lang-switch button.current { background: var(--brand-red); border-color: var(--brand-red); color: #fff; }
.lang-switch.auth { justify-content: center; padding: 16px 0 0; }
.lang-switch.auth button { border-color: var(--border); color: var(--muted); }
.lang-switch.auth button.current { background: var(--brand-navy-2); border-color: var(--brand-navy-2); color: #fff; }
.sidebar .userbox { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.1); font-size: 12.5px; }
.sidebar .userbox .name { color: #fff; font-weight: 600; }
.sidebar .userbox .role { color: #7d84a3; }
.sidebar .userbox a { color: #9fb6e8; }
.sidebar .userbox form { margin-top: 8px; }

/* ---------- main ---------- */
/* min-width: 0 lets the flex column shrink so wide tables scroll inside
   .table-wrap instead of pushing the page past the viewport edge. */
.main { flex: 1; min-width: 0; padding: 24px 28px; max-width: 1500px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: .3px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- cards & KPIs ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; }
.card h2 { margin: 0 0 12px; font-size: 15px; letter-spacing: .4px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  border-top: 3px solid var(--brand-navy);
}
.kpi .num { font-family: var(--font-head); font-size: 27px; font-weight: 700; color: var(--brand-navy); }
.kpi .label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; background: var(--card); }
table.data th, table.data td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td.wrap { white-space: normal; }
table.data th {
  background: #eef0f6; font-family: var(--font-head); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .8px; color: var(--brand-navy-2);
  position: sticky; top: 0;
}
table.data tr:hover td { background: #f6f8fc; }
table.data .num { text-align: right; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 11.5px; font-weight: 600; }
.badge.in_service { background: #e2f3e9; color: var(--ok); }
.badge.in_storage { background: #e8ecf4; color: #47598a; }
.badge.maintenance { background: #fdf1dc; color: var(--warn); }
.badge.retired { background: #efe6e5; color: #7a4a44; }
.badge.disposed { background: #e9e9e9; color: #666; }
.badge.new { background: #fdeaea; color: var(--brand-red); }
.badge.linked { background: #e2f3e9; color: var(--ok); }
.badge.ignored { background: #e9e9e9; color: #666; }
.badge.admin { background: #e4e6f5; color: var(--brand-navy-2); }
.badge.technician { background: #dcebf7; color: #24608f; }
.badge.viewer { background: #e9e9e9; color: #555; }
.badge.danger { background: #fdeaea; color: var(--danger); }
.badge.warn { background: #fdf1dc; color: var(--warn); }
.badge.ok { background: #e2f3e9; color: var(--ok); }

/* ---------- forms ---------- */
form.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
input, select, textarea {
  font: inherit; color: inherit;
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd4f0; border-color: var(--accent-light); }
label { font-size: 12.5px; color: var(--muted); display: block; margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid textarea { width: 100%; min-height: 70px; resize: vertical; }
.form-grid input, .form-grid select { width: 100%; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 16px; padding: 12px 14px; }
legend {
  font-family: var(--font-head); font-size: 12px; font-weight: 600;
  letter-spacing: .8px; text-transform: uppercase;
  color: var(--brand-navy-2); padding: 0 6px;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-block; padding: 7px 14px; border-radius: 6px;
  border: 1px solid var(--brand-navy-2);
  background: var(--brand-navy-2); color: #fff;
  font-family: var(--font-head); font-size: 13.5px; letter-spacing: .4px;
  cursor: pointer;
}
.btn:hover { background: var(--brand-navy); border-color: var(--brand-navy); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--brand-navy-2); }
.btn.secondary:hover { background: #eef1f8; }
.btn.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #fbeeec; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.inline-form { display: inline; }

/* ---------- flashes & alerts ---------- */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 10px; font-size: 13.5px; }
.flash.success { background: #e2f3e9; color: var(--ok); border: 1px solid #bfe3cd; }
.flash.error { background: #fdeaea; color: var(--danger); border: 1px solid #f2c6c1; }
.alert-group { margin-bottom: 4px; }
.alert-group h3 { font-size: 13px; margin: 10px 0 6px; }
.alert-group ul { margin: 0; padding-left: 20px; }
.alert-group li { margin-bottom: 3px; }
.muted { color: var(--muted); }
.empty { color: var(--muted); font-style: italic; padding: 14px 0; }

/* ---------- auth pages ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--brand-navy) 0%, var(--brand-navy-2) 100%);
}
.auth-card {
  background: #fff; border-radius: 10px; padding: 30px 34px;
  width: 420px; max-width: 92vw;
  border-top: 4px solid var(--brand-red);
}
.auth-logo { display: block; width: 250px; max-width: 100%; margin: 4px auto 18px; }
.auth-card h1 { margin: 0 0 4px; font-size: 20px; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.auth-card label { margin-top: 12px; }
.auth-card input { width: 100%; }
.auth-card .btn { width: 100%; margin-top: 18px; }
.policy-hint { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.5; }

/* ---------- misc ---------- */
.progress { background: #e7eaf1; border-radius: 6px; height: 8px; overflow: hidden; min-width: 80px; }
.progress > div { height: 100%; background: var(--ok); }
.progress > div.warn { background: var(--warn); }
.progress > div.danger { background: var(--brand-red); }
.att-row { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--border); }
.att-row:last-child { border-bottom: none; }
.att-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); display: block; }
.att-icon { width: 64px; height: 64px; border-radius: 6px; border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 26px; background: #f6f8fc; flex-shrink: 0; }
.att-meta { flex: 1; min-width: 0; }
.att-meta > a { font-weight: 600; word-break: break-all; }
.kv { display: grid; grid-template-columns: 170px 1fr; row-gap: 7px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
details.panel { margin-bottom: 10px; }
details.panel summary { cursor: pointer; font-weight: 600; font-family: var(--font-head); color: var(--brand-navy-2); padding: 6px 0; }
.tag { font-family: Consolas, monospace; font-size: 13px; }
h2.section { font-size: 15px; margin: 22px 0 10px; letter-spacing: .4px; }
.help { font-size: 12.5px; color: var(--muted); line-height: 1.6; }
code { background: #eef0f6; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

/* ---------- RTL (Arabic) ----------
   Flex/grid rows flip automatically with dir=rtl; these cover the
   physical properties that don't, and disable letter-spacing because
   Arabic script is cursive (spacing disconnects the glyphs). */
[dir="rtl"] .sidebar a.nav-item { border-left: none; border-right: 3px solid transparent; }
[dir="rtl"] .sidebar a.nav-item.active { border-right-color: var(--brand-red); }
[dir="rtl"] table.data th, [dir="rtl"] table.data td { text-align: right; }
[dir="rtl"] table.data .num { text-align: left; }
[dir="rtl"] .app-title, [dir="rtl"] .nav-section, [dir="rtl"] table.data th,
[dir="rtl"] legend, [dir="rtl"] .btn, [dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3 {
  letter-spacing: 0;
}
[dir="rtl"] .alert-group ul { padding-left: 0; padding-right: 20px; }
