/* ==========================================================================
   1. DESIGN TOKENS — Engineering Drawing Sheet (Light Default + Graphite Dark)
   ========================================================================== */

:root {
  /* Sheet surface & ink */
  --paper: #ECEFEA;
  --paper-subtle: #E3E7E1;
  --ink: #171A1D;
  --muted: #5E656B;
  --rule: #B9C0C2;

  /* IEC 60446 phase & conductor colors (sole accents) */
  --l1: #6A4326;
  --l2: #1A1A1A;
  --l3: #8C9196;
  --neutral: #2D6CB5;
  --earth-yellow: #E6BE1C;
  --earth-green: #2F8A57;

  /* Semantic status (fail / warning only) */
  --status-fail: #A62626;
  --status-warn: #8A5300;

  /* Typography */
  --font-heading: "Reem Kufi", "IBM Plex Sans Arabic", sans-serif;
  --font-body: "IBM Plex Sans Arabic", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Modular type scale (ratio ~1.2) */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-md: 1.1875rem;
  --text-lg: 1.4375rem;
  --text-xl: 1.75rem;

  /* 8px spacing scale */
  --space-half: 4px;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 40px;
  --space-6: 48px;

  /* Geometry */
  --radius: 2px;
  --zone-gutter: 24px;
  --earth-stripe: repeating-linear-gradient(
    45deg,
    var(--earth-green) 0 6px,
    var(--earth-yellow) 6px 12px
  );
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16181A;
    --paper-subtle: #1E2124;
    --ink: #E8ECEF;
    --muted: #9BA3AB;
    --rule: #34393F;
    --l2: #D2D6DA;
    --neutral: #6BA5E7;
    --status-fail: #F07171;
    --status-warn: #E8B04B;
  }
}

:root[data-theme="dark"] {
  --paper: #16181A;
  --paper-subtle: #1E2124;
  --ink: #E8ECEF;
  --muted: #9BA3AB;
  --rule: #34393F;
  --l2: #D2D6DA;
  --neutral: #6BA5E7;
  --status-fail: #F07171;
  --status-warn: #E8B04B;
}

/* ==========================================================================
   2. BASE, RESET & RTL TYPOGRAPHY RULES
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.55;
  padding: var(--space-1);
}

a {
  color: var(--neutral);
  text-decoration: underline;
  text-underline-offset: 3px;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--neutral);
  outline-offset: 2px;
}

h1,
h2,
h3 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.25;
  margin: 0;
}

bdi {
  unicode-bidi: isolate;
}

.num,
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}

/* Arabic / RTL: never apply letter-spacing or uppercase transform (breaks cursive joining) */
:lang(ar),
[dir="rtl"],
:lang(ar) h1,
:lang(ar) h2,
:lang(ar) h3,
:lang(ar) th,
:lang(ar) caption,
:lang(ar) label,
:lang(ar) legend,
:lang(ar) button,
:lang(ar) a,
:lang(ar) .wordmark__text,
:lang(ar) .drawing-table caption,
:lang(ar) .sld__caption,
:lang(ar) .plain-toggle,
:lang(ar) .status-tag,
:lang(ar) .verified-badge,
[dir="rtl"] h1,
[dir="rtl"] h2,
[dir="rtl"] h3,
[dir="rtl"] th,
[dir="rtl"] caption,
[dir="rtl"] label,
[dir="rtl"] legend,
[dir="rtl"] button,
[dir="rtl"] a,
[dir="rtl"] .wordmark__text,
[dir="rtl"] .drawing-table caption,
[dir="rtl"] .sld__caption,
[dir="rtl"] .plain-toggle,
[dir="rtl"] .status-tag,
[dir="rtl"] .verified-badge {
  letter-spacing: 0;
  text-transform: none;
}

.skip-link {
  position: absolute;
  inset-block-start: -120px;
  inset-inline-start: var(--space-2);
  padding: var(--space-1) var(--space-2);
  background-color: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  text-decoration: none;
  font-size: var(--text-sm);
  z-index: 100;
}

.skip-link:focus {
  inset-block-start: var(--space-2);
}

/* ==========================================================================
   3. DRAWING SHEET FRAME & ZONE MARKERS (1–6 TOP, A–D SIDE)
   ========================================================================== */

.sheet-frame {
  position: relative;
  min-height: calc(100vh - var(--space-2));
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--ink);
  display: flex;
  flex-direction: column;
  background-color: var(--paper);
}

.sheet-zones-top,
.sheet-zones-side {
  display: none;
}

@media (min-width: 768px) {
  body {
    padding: var(--space-2);
  }

  .sheet-frame {
    min-height: calc(100vh - var(--space-4));
    padding-block-start: var(--zone-gutter);
    padding-inline-start: var(--zone-gutter);
  }

  .sheet-zones-top {
    position: absolute;
    inset-block-start: 0;
    inset-inline: var(--zone-gutter) 0;
    height: var(--zone-gutter);
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    border-block-end: 1px solid var(--rule);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--muted);
    user-select: none;
  }

  .sheet-zones-top span {
    display: flex;
    align-items: center;
    justify-content: center;
    border-inline-end: 1px solid var(--rule);
  }

  .sheet-zones-top span:last-child {
    border-inline-end: 0;
  }

  .sheet-zones-side {
    position: absolute;
    inset-block: var(--zone-gutter) 0;
    inset-inline-start: 0;
    width: var(--zone-gutter);
    display: grid;
    grid-template-rows: repeat(4, 1fr);
    border-inline-end: 1px solid var(--rule);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--muted);
    user-select: none;
  }

  .sheet-zones-side span {
    display: flex;
    align-items: center;
    justify-content: center;
    border-block-end: 1px solid var(--rule);
  }

  .sheet-zones-side span:last-child {
    border-block-end: 0;
  }
}

/* ==========================================================================
   4. HEADER, THREE-PHASE WORDMARK & EARTH-STRIPE DIVIDER
   ========================================================================== */

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding-block: var(--space-2);
  padding-inline: var(--space-2);
  min-width: 0;
}

@media (min-width: 768px) {
  .site-header {
    padding-inline: var(--space-3);
  }
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--ink);
  text-decoration: none;
}

.wordmark__phases {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 24px;
  flex-shrink: 0;
}

.wordmark__line {
  display: block;
  height: 2px;
  width: 100%;
}

.wordmark__line--l1 {
  background-color: var(--l1);
}

.wordmark__line--l2 {
  background-color: var(--l2);
}

.wordmark__line--l3 {
  background-color: var(--l3);
}

.wordmark__text {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.site-header__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.plain-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: 0;
  padding: var(--space-half) 0;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  text-decoration: none;
  cursor: pointer;
}

.plain-toggle__sep {
  color: var(--rule);
  margin-inline: var(--space-half);
}

.plain-toggle__opt--inactive {
  color: var(--muted);
  font-weight: 400;
}

.plain-toggle__opt--active {
  color: var(--ink);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.earth-divider {
  height: 4px;
  width: 100%;
  background-image: var(--earth-stripe);
  border-block-start: 1px solid var(--rule);
  border-block-end: 1px solid var(--rule);
}

/* ==========================================================================
   5. MAIN WORKSPACE & DRAWING INDEX (HOME)
   ========================================================================== */

.sheet-main {
  flex: 1 0 auto;
  min-width: 0;
  max-width: 100%;
  padding-block: var(--space-3);
  padding-inline: var(--space-2);
}

@media (min-width: 768px) {
  .sheet-main {
    padding-block: var(--space-4);
    padding-inline: var(--space-3);
  }
}

.sheet-intro {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-1);
  padding-block-end: var(--space-2);
  margin-block-end: var(--space-3);
  border-block-end: 1px solid var(--rule);
  min-width: 0;
}

.sheet-intro__title {
  font-size: var(--text-xl);
}

.sheet-intro__code {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
}

.sheet-intro__subtitle {
  flex-basis: 100%;
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
  max-width: 68ch;
}

.breadcrumb {
  margin-block-end: var(--space-2);
  font-size: var(--text-sm);
}

/* Scrollable table wrapper + visible narrow-screen hint */
.table-scroll-wrap {
  min-width: 0;
  max-width: 100%;
}

.table-scroll__hint {
  margin: 0 0 var(--space-half);
  font-size: var(--text-xs);
  color: var(--muted);
}

@media (min-width: 768px) {
  .table-scroll__hint {
    display: none;
  }
}

.table-scroll {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--rule);
}

.drawing-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.drawing-table caption {
  caption-side: top;
  text-align: start;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding-block: var(--space-1);
  padding-inline: var(--space-2);
  border-block-end: 1px solid var(--rule);
  background-color: var(--paper-subtle);
}

.drawing-table th,
.drawing-table td {
  padding-block: var(--space-1);
  padding-inline: var(--space-2);
  border-block-end: 1px solid var(--rule);
  border-inline-end: 1px solid var(--rule);
  text-align: start;
  vertical-align: top;
}

.drawing-table tr > :last-child {
  border-inline-end: 0;
}

.drawing-table tbody tr:last-child > * {
  border-block-end: 0;
}

.drawing-table thead th {
  background-color: var(--paper-subtle);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--ink);
}

.drawing-table__num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ==========================================================================
   6. CALCULATOR SHEET LAYOUT (LEFT INPUTS / RIGHT DRAWING SHEET)
   ========================================================================== */

.calc-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
  min-width: 0;
  max-width: 100%;
}

@media (min-width: 960px) {
  .calc-layout {
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    gap: var(--space-4);
  }
}

.calc-inputs {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
  max-width: 100%;
}

.calc-fieldset {
  margin: 0;
  padding: var(--space-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  min-inline-size: 0;
  width: 100%;
  max-width: 100%;
}

.calc-fieldset legend {
  padding-inline: var(--space-1);
  font-family: var(--font-heading);
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--ink);
  max-width: 100%;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-2);
  min-width: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-half);
  min-width: 0;
}

.field__label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink);
}

.field__control {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 40px;
  padding-block: var(--space-1);
  padding-inline: var(--space-1);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.field__control--text {
  font-family: var(--font-body);
}

.field__hint {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--muted);
}

/* Right drawing sheet area */
.calc-sheet {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  border: 1px solid var(--rule);
  padding: var(--space-2);
  min-width: 0;
  max-width: 100%;
}

@media (min-width: 768px) {
  .calc-sheet {
    padding: var(--space-3);
  }
}

/* ==========================================================================
   7. LIVE SINGLE-LINE DIAGRAM (INLINE SVG — VERTICAL <600px, HORIZONTAL >=600px)
   ========================================================================== */

.sld {
  margin: 0;
  border: 1px solid var(--rule);
  padding: var(--space-2);
  background-color: var(--paper);
  min-width: 0;
  max-width: 100%;
}

.sld__caption {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-block-end: var(--space-2);
}

.sld__svg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.sld__line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.5;
}

.sld__dim {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1;
}

.sld__phase-l1 {
  fill: none;
  stroke: var(--l1);
  stroke-width: 2;
}

.sld__phase-l2 {
  fill: none;
  stroke: var(--l2);
  stroke-width: 2;
}

.sld__phase-l3 {
  fill: none;
  stroke: var(--l3);
  stroke-width: 2;
}

.sld__label {
  fill: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  transition: opacity 150ms ease;
}

.sld__label--ar {
  font-family: var(--font-body);
  font-size: 13px;
}

.sld__label--muted {
  fill: var(--muted);
  font-size: 12px;
}

@media (prefers-reduced-motion: reduce) {
  .sld__label {
    transition: none;
  }
}

/* ==========================================================================
   8. CABLE SCHEDULE OUTPUT & STATUS STATES
   ========================================================================== */

.schedule-output {
  display: block;
  min-width: 0;
  max-width: 100%;
}

.schedule-notice {
  margin: 0 0 var(--space-2);
  padding-block: var(--space-1);
  padding-inline: var(--space-2);
  border: 1px solid var(--status-warn);
  border-radius: var(--radius);
  color: var(--status-warn);
  font-size: var(--text-sm);
}

.status-tag {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

.status-tag--pending {
  color: var(--status-warn);
}

.status-tag--fail {
  color: var(--status-fail);
}

.status-tag--pass {
  color: var(--ink);
}

/* ==========================================================================
   9. ENGINEERING TITLE BLOCK (BOTTOM-RIGHT OF SHEET)
   ========================================================================== */

.title-block-wrap {
  margin-block-start: auto;
  display: flex;
  justify-content: flex-end;
  min-width: 0;
  max-width: 100%;
}

.title-block {
  width: 100%;
  max-width: 480px;
  table-layout: fixed;
  border-collapse: collapse;
  border: 1px solid var(--ink);
  font-size: var(--text-xs);
}

.title-block th,
.title-block td {
  border: 1px solid var(--rule);
  padding-block: 6px;
  padding-inline: var(--space-1);
  text-align: start;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.title-block th {
  width: 36%;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--muted);
  background-color: var(--paper-subtle);
}

.title-block td {
  color: var(--ink);
}

.verified-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-family: var(--font-mono);
  font-weight: 600;
}

.verified-badge__stripe {
  display: inline-block;
  width: 24px;
  height: 10px;
  background-image: var(--earth-stripe);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  flex-shrink: 0;
}

/* ==========================================================================
   10. FOOTER & DISCLAIMER
   ========================================================================== */

.sheet-footer {
  border-block-start: 1px solid var(--rule);
  padding-block: var(--space-2);
  padding-inline: var(--space-2);
  font-size: var(--text-xs);
  color: var(--muted);
  min-width: 0;
}

@media (min-width: 768px) {
  .sheet-footer {
    padding-inline: var(--space-3);
  }
}

.sheet-footer p {
  margin: 0;
}

.sheet-footer strong {
  font-family: var(--font-mono);
  color: var(--ink);
}
