/*
 * اعتبارسازه — application stylesheet (UI shell v0.1)
 *
 * Brand tokens come from .claude/brand/tokens.json of the study vault (navy = primary,
 * copper = accent) and the interactive-prototype spec. Components mirror the prototype
 * vocabulary (card, kpi, badge, notice, data-table) so real pages look like the demo.
 *
 * Contrast rules (WCAG AA): copper #B06A2C is 4.25:1 on white, so it is used only for
 * decoration, large numbers and fills; small copper text uses --copper-700. Warning amber
 * likewise uses --warn-700 for text.
 */

/* ===== Fonts ===== */
@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn-Regular.e8e9648f5b8f.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn-Bold.4ac4426bc38f.ttf") format("truetype");
  font-weight: 700 800;
  font-style: normal;
  font-display: swap;
}

/* ===== Tokens ===== */
:root {
  color-scheme: light;

  --navy-900: #0b1f3a;
  --navy-700: #14325c;
  --navy-500: #2b5288;
  --navy-100: #e7edf6;
  --copper-700: #8a4f1c; /* text-safe copper (6.5:1 on white) */
  --copper-600: #b06a2c;
  --copper-100: #f7ebdf;

  --ink: #1b1f24;
  --muted: #5b6470;
  --line: #e3e6eb;
  --line-strong: #c9ced6;
  --input-border: #838c99; /* 3.4:1 on white: form control boundary (WCAG 1.4.11) */
  --surface: #ffffff;
  --surface-2: #f5f6f8;

  --good: #1f7a4d;
  --good-700: #165c3a;
  --good-100: #e6f2eb;
  --warn: #b7791f;
  --warn-700: #7a5212;
  --warn-100: #fbf1dc;
  --bad: #b3261e;
  --bad-700: #9a2019;
  --bad-100: #fbeae8;

  --focus: #2b5288;

  --font: "Vazirmatn", "Vazir", "IRANSans", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(11, 31, 58, 0.06);
  --shadow-lg: 0 8px 24px rgba(11, 31, 58, 0.1);
  --gutter: 16px;
  --container: 1100px;
}

/* ===== Base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.75;
  direction: rtl;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}
h1,
h2,
h3,
h4 {
  margin: 0 0 0.5em;
  color: var(--navy-900);
  line-height: 1.45;
  font-weight: 800;
}
h1 {
  font-size: 1.6rem;
}
h2 {
  font-size: 1.25rem;
}
h3 {
  font-size: 1.05rem;
  font-weight: 700;
}
p {
  margin: 0 0 1em;
}
a {
  color: var(--navy-500);
  text-underline-offset: 3px;
}
a:hover {
  color: var(--navy-700);
}
img,
svg {
  max-width: 100%;
}
hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 20px 0;
}
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* ===== Accessibility helpers ===== */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  inset-inline-start: 12px;
  top: -100px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--navy-900);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}
.skip-link:focus {
  top: 12px;
  color: #fff;
}

/* ===== Environment ribbon (every environment except production) ===== */
.env-ribbon {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px var(--gutter);
  background: repeating-linear-gradient(
    -45deg,
    var(--warn-100),
    var(--warn-100) 12px,
    #f6e6c4 12px,
    #f6e6c4 24px
  );
  border-bottom: 1px solid #e8cf9c;
  color: var(--warn-700);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}
.env-ribbon .env-name {
  padding: 0 8px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.6;
}

/* ===== App bar ===== */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.app-bar-inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding-block: 10px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--navy-900);
  text-decoration: none;
  flex: none;
}
.brand:hover {
  color: var(--navy-900);
}
.brand-mark {
  width: 32px;
  height: 32px;
  flex: none;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}
.brand-name {
  font-size: 19px;
  font-weight: 800;
}
.brand-tag {
  font-size: 11px;
  color: var(--muted);
}
.main-nav {
  order: 3;
  flex: 1 0 100%;
}
.main-nav ul {
  display: flex;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
}
.main-nav a {
  display: inline-block;
  padding: 6px 10px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}
.main-nav a:hover {
  color: var(--navy-900);
}
.main-nav a[aria-current="page"] {
  color: var(--navy-900);
  font-weight: 700;
  border-bottom-color: var(--copper-600);
}
.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-inline-start: auto;
  min-width: 0;
}
.user-name {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 14ch;
}
.user-menu form {
  margin: 0;
}
@media (max-width: 479px) {
  .brand-tag {
    display: none;
  }
  .brand-name {
    font-size: 18px;
  }
  .user-name {
    max-width: 11ch;
  }
}
@media (min-width: 720px) {
  .main-nav {
    order: 0;
    flex: 1 1 auto;
  }
  .user-name {
    max-width: 24ch;
  }
}

/* ===== Layout ===== */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.site-main {
  flex: 1;
  padding-block: 24px 40px;
}
.site-main:focus {
  outline: none;
}
.narrow {
  max-width: 440px;
  margin-inline: auto;
}
.stack > * + * {
  margin-top: 16px;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 18px;
}
.page-kicker {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}
.page-title {
  margin: 0;
  font-size: 1.5rem;
}
.page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
@media (min-width: 820px) {
  .content-grid {
    grid-template-columns: repeat(12, minmax(0, 1fr));
  }
  .content-grid > * {
    grid-column: span 12;
  }
  .content-grid > .col-4 {
    grid-column: span 4;
  }
  .content-grid > .col-6 {
    grid-column: span 6;
  }
  .content-grid > .col-8 {
    grid-column: span 8;
  }
}

/* ===== Footer ===== */
.site-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}
.site-footer .container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 16px;
  padding-block: 14px;
}
.site-footer p {
  margin: 0;
}

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}
.card + .card {
  margin-top: 14px;
}
.content-grid > .card + .card {
  margin-top: 0;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--navy-900);
}
.card-subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.card-footer {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.card-accent {
  border-top: 3px solid var(--copper-600);
}

/* ===== KPI tiles ===== */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 15px 12px;
}
.kpi::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--line);
}
.kpi-label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}
.kpi-value {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.2;
  color: var(--navy-900);
  font-variant-numeric: tabular-nums;
}
.kpi-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}
.kpi-accent::before {
  background: var(--copper-600);
}
.kpi-accent .kpi-value {
  color: var(--copper-600); /* 24px bold = large text, 4.25:1 passes AA */
}
.kpi-good::before {
  background: var(--good);
}
.kpi-good .kpi-value {
  color: var(--good);
}
.kpi-warn::before {
  background: var(--warn);
}
.kpi-warn .kpi-value {
  color: var(--warn-700);
}
.kpi-bad::before {
  background: var(--bad);
}
.kpi-bad .kpi-value {
  color: var(--bad);
}

/* ===== Data table ===== */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table caption {
  caption-side: top;
  padding: 10px 12px 6px;
  text-align: start;
  font-weight: 700;
  color: var(--navy-900);
}
.data-table th,
.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: top;
}
.data-table thead th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.data-table tbody tr:nth-child(even) {
  background: #fafbfc;
}
.data-table tbody tr:hover {
  background: var(--navy-100);
}
.data-table tbody tr:last-child td,
.data-table tbody tr:last-child th {
  border-bottom: 0;
}
.data-table .num {
  text-align: left;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.data-table th,
.data-table td {
  white-space: nowrap;
}
.data-table td.wide,
.data-table td.wrap {
  white-space: normal;
  min-width: 180px;
}
.data-table tfoot td,
.data-table tfoot th,
.data-table tr.is-total td,
.data-table tr.is-total th {
  font-weight: 700;
  background: var(--surface-2);
  border-top: 2px solid var(--line-strong);
  border-bottom: 0;
}
.data-table td.empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--muted);
}
.data-table a {
  font-weight: 700;
}

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.7;
  white-space: nowrap;
  vertical-align: middle;
}
/* Status variants (domain meaning) */
.badge-open {
  color: var(--navy-700);
  border-color: var(--navy-500);
  background: var(--navy-100);
}
.badge-completed,
.badge-good {
  color: var(--good-700);
  border-color: var(--good);
  background: var(--good-100);
}
.badge-closed,
.badge-neutral {
  color: var(--muted);
  border-color: var(--line-strong);
  background: var(--surface-2);
}
.badge-overdue,
.badge-bad {
  color: var(--bad-700);
  border-color: var(--bad);
  background: var(--bad-100);
}
.badge-warn {
  color: var(--warn-700);
  border-color: var(--warn);
  background: var(--warn-100);
}
.badge-accent,
.badge-role {
  color: var(--copper-700);
  border-color: var(--copper-600);
  background: var(--copper-100);
}

.badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 7px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--navy-700);
  border-color: var(--navy-700);
  color: #fff;
}
.btn-primary:hover {
  background: var(--navy-500);
  border-color: var(--navy-500);
  color: #fff;
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--navy-700);
}
.btn-ghost:hover {
  background: var(--navy-100);
  color: var(--navy-900);
}
.btn-danger {
  background: var(--surface);
  border-color: var(--bad);
  color: var(--bad-700);
}
.btn-danger:hover {
  background: var(--bad-100);
  color: var(--bad-700);
}
.btn-sm {
  min-height: 32px;
  padding: 4px 11px;
  font-size: 13px;
}
.btn-block {
  display: flex;
  width: 100%;
}

/* ===== Forms ===== */
.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label,
.field .label {
  font-size: 14px;
  font-weight: 700;
  color: var(--navy-900);
}
.field .required::after {
  content: " *";
  color: var(--bad-700);
}
input:not([type="checkbox"], [type="radio"], [type="hidden"], [type="submit"]),
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 0;
  border-color: var(--focus);
}
input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--bad);
}
input[dir="ltr"],
.ltr-input {
  text-align: left;
}
.field-help {
  font-size: 13px;
  color: var(--muted);
}
.field-error,
.errorlist {
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--bad-700);
  font-size: 13px;
  font-weight: 700;
}
.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ===== Alerts and notices ===== */
.messages {
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}
.alert {
  border: 1px solid var(--navy-500);
  border-inline-start-width: 4px;
  border-radius: var(--radius-sm);
  background: var(--navy-100);
  color: var(--navy-900);
  padding: 10px 14px;
  font-size: 14px;
}
.alert + .alert {
  margin-top: 8px;
}
.alert p:last-child,
.alert ul:last-child {
  margin-bottom: 0;
}
.alert-success {
  border-color: var(--good);
  background: var(--good-100);
  color: var(--good-700);
}
.alert-warning {
  border-color: var(--warn);
  background: var(--warn-100);
  color: var(--warn-700);
}
.alert-danger,
.alert-error {
  border-color: var(--bad);
  background: var(--bad-100);
  color: var(--bad-700);
}
.notice {
  margin: 10px 0;
  padding: 10px 12px;
  border-inline-start: 3px solid var(--muted);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 14px;
}
.notice-accent {
  border-color: var(--copper-600);
  background: var(--copper-100);
  color: var(--navy-900);
  font-weight: 700;
}
.notice-good {
  border-color: var(--good);
}
.notice-warn {
  border-color: var(--warn);
}
.notice-bad {
  border-color: var(--bad);
}

/* ===== Progress (physical = navy, financial = copper, everywhere) ===== */
.progress {
  height: 6px;
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
}
.progress-fill {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--navy-700);
}
.progress-fill.is-financial {
  background: var(--copper-600);
}

/* ===== Key/value list ===== */
.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  margin: 0;
  font-size: 14px;
}
.kv dt {
  color: var(--muted);
}
.kv dd {
  margin: 0;
  font-weight: 700;
}

/* ===== Home ===== */
.hero {
  padding: 28px 0 8px;
}
.hero-title {
  font-size: clamp(1.5rem, 5vw, 2.1rem);
  margin-bottom: 10px;
}
.hero-rule {
  width: 40px;
  height: 3px;
  margin: 0 0 14px;
  border: 0;
  border-radius: 2px;
  background: var(--copper-600);
}
.hero-lead {
  max-width: 40rem;
  font-size: 17px;
  color: var(--ink);
}
.feature-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 12px;
  margin: 24px 0;
  padding: 0;
  list-style: none;
}
.feature-list .card {
  margin: 0;
  height: 100%;
}
.feature-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  font-size: 16px;
}
.feature-list p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* ===== Utilities ===== */
.muted {
  color: var(--muted);
}
.num,
.tabular {
  font-variant-numeric: tabular-nums;
}
.ltr {
  direction: ltr;
  unicode-bidi: isolate;
}
.nowrap {
  white-space: nowrap;
}
.text-center {
  text-align: center;
}
.mt-0 {
  margin-top: 0;
}
.mb-0 {
  margin-bottom: 0;
}
.mt-3 {
  margin-top: 12px;
}

/* Progress bar inside a table cell */
.data-table .progress {
  display: block;
  min-width: 96px;
  margin-top: 4px;
}

/* Large KPI figures stay on one line even in a two-column phone grid */
.kpi-value {
  white-space: nowrap;
  font-size: clamp(17px, 5.4vw, 24px);
}
@media (min-width: 640px) {
  .kpi-value {
    font-size: 24px;
  }
}

/* Hidden SVG sprite (was an inline style; the CSP forbids style attributes) */
.svg-sprite {
  position: absolute;
}

/* Native <progress> for data-driven bars (no inline width under the CSP) */
progress.progress.is-native {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  border: 0;
  color: var(--navy-700);
  background: var(--line);
}
progress.progress.is-native::-webkit-progress-bar {
  background: var(--line);
}
progress.progress.is-native::-webkit-progress-value {
  background: var(--navy-700);
  border-radius: 4px;
}
progress.progress.is-native::-moz-progress-bar {
  background: var(--navy-700);
  border-radius: 4px;
}
