/* Iconia Order Management System
   Single stylesheet, no build step, no framework.

   Three things this file has to get right:
   - responsive down to a phone, because technicians use it on site
   - light and dark, driven by [data-theme] with prefers-color-scheme as the
     default when the user has not chosen
   - English (LTR) and Arabic (RTL) from the same rules, which is why spacing
     and alignment use logical properties (margin-inline-start, text-align:
     start/end) rather than left/right. Add a `left`/`right` here and the
     Arabic layout will quietly break. */

:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #dfe3e8;
  --text: #1c2430;
  --muted: #6b7683;
  --brand: #12467b;
  --brand-dark: #0d3358;
  --brand-text: #ffffff;
  --nav-link: #dbe6f2;
  --accent: #1a7f5a;
  --danger: #b3261e;
  --warn: #a05e03;
  --info: #1f5f9e;

  --pill-neutral-bg: #eef1f4;  --pill-neutral-fg: #4a5560;
  --pill-info-bg: #e6f0fa;     --pill-info-fg: #1f5f9e;
  --pill-progress-bg: #e8f1fc; --pill-progress-fg: #14539a;
  --pill-warn-bg: #fdf1de;     --pill-warn-fg: #a05e03;
  --pill-good-bg: #e4f4ec;     --pill-good-fg: #1a7f5a;
  --pill-bad-bg: #fbe9e7;      --pill-bad-fg: #b3261e;
  --pill-muted-bg: #f0f0f0;    --pill-muted-fg: #757575;

  --flash-success-bg: #e4f4ec; --flash-success-bd: #b6dfc9; --flash-success-fg: #14603f;
  --flash-error-bg: #fbe9e7;   --flash-error-bd: #eebfba;   --flash-error-fg: #8c1d18;
  --flash-warning-bg: #fdf1de; --flash-warning-bd: #f0d3a0; --flash-warning-fg: #7a4703;

  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

/* Explicit dark choice. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12161c;
  --surface: #1a2029;
  --surface-2: #1f2630;
  --border: #2c3542;
  --text: #e6eaef;
  --muted: #98a3b1;
  --brand: #2b6cb0;
  --brand-dark: #1d4f85;
  --brand-text: #ffffff;
  --nav-link: #cfe0f2;
  --accent: #3fbf8c;
  --danger: #f2837a;
  --warn: #e0a458;
  --info: #6fb0ea;

  --pill-neutral-bg: #262f3b;  --pill-neutral-fg: #b6c0cc;
  --pill-info-bg: #1c3a57;     --pill-info-fg: #8cc3f0;
  --pill-progress-bg: #1b3b5e; --pill-progress-fg: #93c5f5;
  --pill-warn-bg: #45330f;     --pill-warn-fg: #e8bd7a;
  --pill-good-bg: #143d2c;     --pill-good-fg: #66d3a4;
  --pill-bad-bg: #4a221f;      --pill-bad-fg: #f4a09a;
  --pill-muted-bg: #262b32;    --pill-muted-fg: #99a1ab;

  --flash-success-bg: #143d2c; --flash-success-bd: #22694b; --flash-success-fg: #7fdcb0;
  --flash-error-bg: #4a221f;   --flash-error-bd: #7d3a35;   --flash-error-fg: #f6b0aa;
  --flash-warning-bg: #45330f; --flash-warning-bd: #77571c; --flash-warning-fg: #ecc689;

  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3);
}

/* No explicit choice: follow the operating system. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12161c;
    --surface: #1a2029;
    --surface-2: #1f2630;
    --border: #2c3542;
    --text: #e6eaef;
    --muted: #98a3b1;
    --brand: #2b6cb0;
    --brand-dark: #1d4f85;
    --nav-link: #cfe0f2;
    --accent: #3fbf8c;
    --danger: #f2837a;
    --warn: #e0a458;
    --info: #6fb0ea;

    --pill-neutral-bg: #262f3b;  --pill-neutral-fg: #b6c0cc;
    --pill-info-bg: #1c3a57;     --pill-info-fg: #8cc3f0;
    --pill-progress-bg: #1b3b5e; --pill-progress-fg: #93c5f5;
    --pill-warn-bg: #45330f;     --pill-warn-fg: #e8bd7a;
    --pill-good-bg: #143d2c;     --pill-good-fg: #66d3a4;
    --pill-bad-bg: #4a221f;      --pill-bad-fg: #f4a09a;
    --pill-muted-bg: #262b32;    --pill-muted-fg: #99a1ab;

    --flash-success-bg: #143d2c; --flash-success-bd: #22694b; --flash-success-fg: #7fdcb0;
    --flash-error-bg: #4a221f;   --flash-error-bd: #7d3a35;   --flash-error-fg: #f6b0aa;
    --flash-warning-bg: #45330f; --flash-warning-bd: #77571c; --flash-warning-fg: #ecc689;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

/* Arabic needs slightly more line height and a font stack that actually has
   Arabic glyphs on Windows and macOS. */
html[lang="ar"] body {
  font-family: "Segoe UI", Tahoma, "Dubai", "Noto Naskh Arabic", "Geeza Pro", Arial, sans-serif;
  line-height: 1.75;
}

a { color: var(--brand); }
a:hover { color: var(--brand-dark); }
:root[data-theme="dark"] a:hover { color: #7fb3e8; }

/* --- layout ------------------------------------------------------------ */

.topbar { background: var(--brand); color: var(--brand-text); padding: 0 16px; }
.topbar-inner {
  max-width: 1180px; margin: 0 auto;
  display: flex; align-items: center; gap: 18px;
  min-height: 56px; flex-wrap: wrap;
}
.brand {
  font-weight: 700; font-size: 17px; color: var(--brand-text);
  text-decoration: none; letter-spacing: .2px; white-space: nowrap;
  display: flex; align-items: center; gap: 10px;
}
.brand small { display: block; font-weight: 400; font-size: 11px; opacity: .75; }
/* Width auto keeps the aspect ratio; the width/height attributes on the tag
   are there to reserve space and stop the topbar jumping as it loads. */
.brand-logo { height: 34px; width: auto; display: block; }
.brand-text {
  font-weight: 400; font-size: 12px; opacity: .8;
  padding-inline-start: 10px; border-inline-start: 1px solid rgba(255, 255, 255, .25);
}

.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a {
  color: var(--nav-link); text-decoration: none;
  padding: 7px 11px; border-radius: 6px; font-size: 14px; white-space: nowrap;
}
.nav a:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.nav a.active { background: rgba(255, 255, 255, .18); color: #fff; font-weight: 600; }

.topbar-user { display: flex; align-items: center; gap: 8px; font-size: 13px; flex-wrap: wrap; }
.topbar-user .who { opacity: .85; }

/* Language + theme controls */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(255, 255, 255, .14); color: #fff;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 6px; padding: 5px 9px;
  font: inherit; font-size: 13px; cursor: pointer; text-decoration: none;
}
.chip:hover { background: rgba(255, 255, 255, .24); color: #fff; }
.chip.on { background: rgba(255, 255, 255, .3); font-weight: 600; }
.lang-group { display: inline-flex; border-radius: 6px; overflow: hidden; }
.lang-group .chip { border-radius: 0; border-inline-end: none; }
.lang-group .chip:first-child { border-start-start-radius: 6px; border-end-start-radius: 6px; }
.lang-group .chip:last-child {
  border-start-end-radius: 6px; border-end-end-radius: 6px;
  border-inline-end: 1px solid rgba(255, 255, 255, .22);
}

.container { max-width: 1180px; margin: 0 auto; padding: 22px 16px 60px; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-head h1 { margin: 0 0 4px; font-size: 22px; }
.page-head .sub { color: var(--muted); font-size: 14px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- cards -------------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px;
}
.card-head {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.card-head h2 {
  margin: 0; font-size: 15px; text-transform: uppercase;
  letter-spacing: .4px; color: var(--muted);
}
html[lang="ar"] .card-head h2 { text-transform: none; letter-spacing: 0; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* --- KPI tiles ---------------------------------------------------------- */

.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.kpi .label {
  font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
}
html[lang="ar"] .kpi .label { text-transform: none; letter-spacing: 0; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.good .value { color: var(--accent); }
.kpi.bad .value { color: var(--danger); }

/* KPI tiles are links into the rows behind the figure. Keep the text colour
   of a plain tile so they do not read as a wall of hyperlinks, and carry the
   affordance on hover/focus instead. */
a.kpi { display: block; text-decoration: none; color: var(--text); transition: border-color .12s, box-shadow .12s, transform .12s; }
a.kpi:hover { border-color: var(--brand); box-shadow: 0 2px 10px rgba(0, 0, 0, .09); transform: translateY(-1px); }
a.kpi:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
a.kpi::after {
  content: "›"; float: inline-end; color: var(--muted);
  font-size: 16px; line-height: 1; opacity: 0; transition: opacity .12s;
}
a.kpi:hover::after { opacity: 1; }
[dir="rtl"] a.kpi::after { content: "‹"; }

/* --- tables ------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td {
  padding: 10px 12px; text-align: start;
  border-bottom: 1px solid var(--border); vertical-align: top;
}
th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); font-weight: 600; white-space: nowrap;
}
html[lang="ar"] th { text-transform: none; letter-spacing: 0; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
/* Figures stay end-aligned and tabular in both directions. */
td.num, th.num { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* Amounts and other Latin/numeric runs must not be reordered by the RTL
   bidi algorithm -- without this, "AED -1,200.00" renders scrambled. */
[dir="rtl"] .num, [dir="rtl"] .money, [dir="rtl"] .ltr {
  direction: ltr; unicode-bidi: embed; text-align: end;
}

/* --- badges / pills ----------------------------------------------------- */

.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.pill.neutral  { background: var(--pill-neutral-bg);  color: var(--pill-neutral-fg); }
.pill.info     { background: var(--pill-info-bg);     color: var(--pill-info-fg); }
.pill.progress { background: var(--pill-progress-bg); color: var(--pill-progress-fg); }
.pill.warn     { background: var(--pill-warn-bg);     color: var(--pill-warn-fg); }
.pill.good     { background: var(--pill-good-bg);     color: var(--pill-good-fg); }
.pill.bad      { background: var(--pill-bad-bg);      color: var(--pill-bad-fg); }
.pill.muted    { background: var(--pill-muted-bg);    color: var(--pill-muted-fg); }

.tag { font-size: 12px; color: var(--muted); }
.flag {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px;
  border-radius: 4px; background: var(--pill-bad-bg); color: var(--pill-bad-fg);
  text-transform: uppercase; letter-spacing: .3px;
}
.flag.warn { background: var(--pill-warn-bg); color: var(--pill-warn-fg); }
html[lang="ar"] .flag { text-transform: none; letter-spacing: 0; }

/* --- forms -------------------------------------------------------------- */

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 4px; }

input[type=text], input[type=password], input[type=email], input[type=date],
input[type=number], input[type=search], input[type=tel], select, textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  font: inherit; background: var(--surface); color: var(--text);
}
input[type=file] { color: var(--text); font: inherit; font-size: 13px; max-width: 100%; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(43, 108, 176, .35); border-color: var(--brand);
}
textarea { min-height: 76px; resize: vertical; }
select[multiple] { min-height: 120px; }
/* Amount fields read left-to-right even in Arabic. */
input[inputmode=decimal], input[type=date] { direction: ltr; text-align: start; }

.field-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.check { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 9px; font-size: 14px; }
.check input { margin-top: 3px; flex-shrink: 0; }
.check .help { font-size: 12px; color: var(--muted); }

.btn {
  display: inline-block; padding: 8px 14px; border-radius: 6px;
  border: 1px solid var(--brand); background: var(--brand); color: var(--brand-text);
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn.secondary { background: var(--surface); color: var(--brand); }
.btn.secondary:hover { background: var(--surface-2); color: var(--brand-dark); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.inline-form { display: inline; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; align-items: center; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin-bottom: 0; min-width: 150px; }

/* --- flash messages ----------------------------------------------------- */

.flash { padding: 11px 14px; border-radius: 6px; margin-bottom: 12px; font-size: 14px; border: 1px solid; }
.flash.success { background: var(--flash-success-bg); border-color: var(--flash-success-bd); color: var(--flash-success-fg); }
.flash.error   { background: var(--flash-error-bg);   border-color: var(--flash-error-bd);   color: var(--flash-error-fg); }
.flash.warning { background: var(--flash-warning-bg); border-color: var(--flash-warning-bd); color: var(--flash-warning-fg); }

/* --- misc --------------------------------------------------------------- */

.meta-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.meta-list dt { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
html[lang="ar"] .meta-list dt { text-transform: none; letter-spacing: 0; }
.meta-list dd { margin: 3px 0 0; font-weight: 500; }

.hidden-note {
  font-size: 13px; color: var(--muted); font-style: italic;
  padding: 10px 12px; background: var(--surface-2);
  border-radius: 6px; border: 1px dashed var(--border);
}

/* Scrolls rather than crushes when the period asks for 18 months of bars. */
.bar-chart {
  display: flex; align-items: flex-end; gap: 10px;
  height: 190px; padding: 8px 4px 0; overflow-x: auto;
}
.bar-group {
  flex: 1 0 44px; display: flex; flex-direction: column; align-items: center;
  gap: 6px; height: 100%; justify-content: flex-end;
}
.bars { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bar { flex: 1 1 auto; max-width: 22px; border-radius: 3px 3px 0 0; min-height: 2px; }
.bar.revenue { background: var(--brand); }
.bar.profit { background: var(--accent); }
.bar.loss { background: var(--danger); }
.bar-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
/* Bars drill into their own month. */
a.bar-group { text-decoration: none; border-radius: 5px; padding-bottom: 2px; }
a.bar-group:hover { background: var(--surface-2); }
a.bar-group:hover .bar-label { color: var(--text); }
a.bar-group:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 10px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: 5px; }

.pipeline { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.pipeline a {
  display: block; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 6px; text-decoration: none; color: var(--text); background: var(--surface);
}
.pipeline a:hover { border-color: var(--brand); }
.pipeline .count { font-size: 20px; font-weight: 700; }
.pipeline .name { font-size: 12px; color: var(--muted); }

.attention-item {
  padding: 11px 16px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 12px;
  align-items: center; flex-wrap: wrap;
}
.attention-item:last-child { border-bottom: none; }
.attention-item .what { font-size: 14px; }
.attention-item .when { font-size: 12px; color: var(--muted); }

.line-items td { padding: 6px 8px; }
.line-items input, .line-items select { padding: 6px 8px; font-size: 14px; }
.line-items .col-desc { width: 42%; }
.line-items .col-qty  { width: 90px; }
.line-items .col-unit { width: 110px; }
.line-items .col-rate { width: 120px; }

/* Sits at the inline end in both directions. */
.totals { margin-inline-start: auto; max-width: 340px; font-size: 14px; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; gap: 16px; }
.totals .grand {
  border-top: 2px solid var(--text); margin-top: 6px;
  padding-top: 8px; font-weight: 700; font-size: 16px;
}

.auth-page { max-width: 380px; margin: 8vh auto; padding: 0 16px; }
.auth-page h1 { font-size: 20px; margin: 0 0 4px; }
.auth-page .sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.auth-lang { text-align: center; margin-top: 16px; font-size: 13px; }
.auth-lang a { margin: 0 6px; }

.auth-brand {
  background: var(--brand); border-radius: var(--radius);
  padding: 22px 26px; margin-bottom: 10px; text-align: center;
}
.auth-brand img { height: 62px; width: auto; display: inline-block; }

/* States the definition behind a figure, above its rows. */
.basis-note {
  background: var(--surface-2); border: 1px solid var(--border);
  border-inline-start: 3px solid var(--brand); border-radius: 6px;
  padding: 10px 13px; font-size: 13px; color: var(--muted); margin-bottom: 14px;
}
.muted-cell { color: var(--muted); font-size: 13px; }
tfoot th { border-top: 2px solid var(--border); border-bottom: none; font-weight: 700; }

.demo-banner {
  background: var(--pill-warn-bg); color: var(--pill-warn-fg);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 9px 13px; font-size: 13px; margin-bottom: 14px;
}

@media (max-width: 640px) {
  .topbar-inner { min-height: auto; padding: 10px 0; }
  .nav { order: 3; width: 100%; }
  .page-head { flex-direction: column; }
  th, td { padding: 9px 10px; }
}

@media print {
  .topbar, .page-actions, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .container { max-width: none; padding: 0; }
  .card { border: none; box-shadow: none; }
}
