/*
 * Ali Dayi — app styling.
 *
 * Two visual worlds live here and they must not bleed into each other:
 *   1. the app chrome  — dark navy, large tap targets, built for a phone held
 *                        in a gloved hand in bright sun
 *   2. the .sheet      — a pixel-accurate rendering of the workbook, sized in
 *                        the workbook's own units and scaled by transform
 */

@font-face {
  font-family: 'Roboto Condensed';
  src: url('fonts/RobotoCondensed-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Roboto Condensed';
  src: url('fonts/RobotoCondensed-Bold.ttf') format('truetype');
  font-weight: 700;
  font-display: swap;
}

:root {
  --ink: #0e1a26;
  --navy: #112233;
  --navy-2: #1b3247;
  --line: #d8dee6;
  --line-2: #eef1f5;
  --paper: #f4f6f9;
  --card: #ffffff;
  --accent: #d62828;
  --accent-dark: #ab1f1f;
  --ok: #1f7a4d;
  --muted: #64748b;
  --radius: 10px;
  --tap: 46px;
  --ui: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

/*
 * A class selector beats the UA's [hidden] rule, so any element given a
 * display value stays visible when hidden — which silently left the busy
 * overlay covering the whole app. Keep this above every display declaration.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------------- appbar */

.appbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--navy);
  color: #fff;
  padding-top: env(safe-area-inset-top);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .25);
}
.appbar-in {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  background: var(--accent);
  border-radius: 8px;
  font-weight: 700; font-size: 14px; letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 17px; letter-spacing: .2px; }
.brand-text small { font-size: 11.5px; color: #9fb3c8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  width: var(--tap); height: 40px;
  border: 0; border-radius: 8px;
  background: rgba(255, 255, 255, .10);
  color: #fff; font-size: 19px; cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .18); }
.appbar-actions { display: flex; gap: 6px; }

/* ----------------------------------------------------------------- layout */

.view { max-width: 1180px; margin: 0 auto; padding: 14px 12px 96px; }

.page-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin: 6px 2px 12px;
}
.page-head h1 { font-size: 20px; margin: 0; letter-spacing: .2px; }
.page-head .sub { color: var(--muted); font-size: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 12px;
}
.card-pad { padding: 14px; }
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-2);
  font-weight: 600; font-size: 14px;
}
.card-head .grow { flex: 1; }

/* ------------------------------------------------------------------ forms */

.field { display: block; margin-bottom: 12px; }
.field > span {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 5px;
}
input[type=text], input[type=date], input[type=number], textarea, select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 16px;                /* keeps iOS from zooming on focus */
  color: var(--ink);
}
textarea { min-height: 92px; resize: vertical; line-height: 1.4; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid #2f6fb3; outline-offset: 1px; border-color: #2f6fb3;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff; color: var(--ink);
  font: inherit; font-weight: 600; font-size: 15px;
  cursor: pointer;
}
.btn:hover { background: #f7f9fc; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-dark { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-dark:hover { background: var(--navy-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #eef2f7; color: var(--ink); }
.btn-sm { min-height: 36px; padding: 0 11px; font-size: 13.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ------------------------------------------------------------ report list */

.report-card { display: flex; align-items: stretch; gap: 0; overflow: hidden; }
.report-main {
  flex: 1; min-width: 0; padding: 13px 14px;
  background: none; border: 0; text-align: left; font: inherit; cursor: pointer;
}
.report-main:hover { background: #f7f9fc; }
.report-no { font-weight: 700; font-size: 16px; }
.report-proj {
  color: var(--ink); font-size: 13.5px; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.report-meta { color: var(--muted); font-size: 12.5px; margin-top: 5px; }
.report-side {
  display: flex; flex-direction: column; justify-content: center; gap: 6px;
  padding: 8px 10px; border-left: 1px solid var(--line-2); background: #fbfcfe;
}

.empty { text-align: center; color: var(--muted); padding: 44px 20px; }
.empty h2 { color: var(--ink); font-size: 17px; margin: 0 0 6px; }
.empty p { margin: 0 0 18px; font-size: 14px; }

/* ------------------------------------------------------------- item cards */

.item-card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; margin-bottom: 12px; }
.item-head {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px 9px 12px; border-bottom: 1px solid var(--line-2);
}
.item-num {
  width: 28px; height: 28px; flex: none; border-radius: 7px;
  background: var(--navy); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.item-title { flex: 1; min-width: 0; font-size: 13.5px; color: var(--muted); }
.item-body { padding: 12px; }

.mat-table { width: 100%; border-collapse: collapse; }
.mat-table th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); text-align: left; padding: 0 0 5px 0; font-weight: 600;
}
.mat-table td { padding: 0 0 7px 0; vertical-align: top; }
.mat-table td + td { padding-left: 7px; }
.mat-table input { min-height: 42px; padding: 8px 10px; }
.mat-table .c-qty { width: 84px; }
.mat-table .c-unit { width: 84px; }
.mat-table .c-del { width: 40px; }
.mat-del {
  width: 38px; height: 42px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--muted); cursor: pointer; font-size: 17px; line-height: 1;
}
.mat-del:hover { border-color: var(--accent); color: var(--accent); }

/* ---------------------------------------------------------------- photos */

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 4px; }
.photo-slot {
  position: relative;
  aspect-ratio: 133 / 180;              /* the printed photo cell proportions */
  border: 1.5px dashed var(--line);
  border-radius: 9px;
  background: #f8fafc;
  display: grid; place-items: center;
  overflow: hidden; cursor: pointer;
}
.photo-slot.filled { border-style: solid; border-color: var(--line); background: #000; }
.photo-slot img { width: 100%; height: 100%; object-fit: contain; display: block; }
.photo-slot .plus { color: var(--muted); font-size: 24px; line-height: 1; }
.photo-slot .cap {
  position: absolute; bottom: 5px; left: 0; right: 0;
  text-align: center; font-size: 10.5px; color: var(--muted);
}
.photo-del {
  position: absolute; top: 5px; right: 5px;
  width: 28px; height: 28px; border-radius: 7px;
  border: 0; background: rgba(0, 0, 0, .62); color: #fff;
  font-size: 15px; line-height: 1; cursor: pointer;
}

/* --------------------------------------------------------------- actions */

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
}
.actionbar-in {
  max-width: 1180px; margin: 0 auto;
  display: flex; gap: 8px;
}
.actionbar .btn { flex: 1; }

/* --------------------------------------------------------------- preview */

.preview-scroll {
  background: #5b6572;
  border-radius: var(--radius);
  padding: 16px 10px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.sheet-stage { position: relative; margin: 0 auto; }
.sheet-scaler { transform-origin: top left; position: absolute; top: 0; left: 0; }
.sheet-pages { display: flex; flex-direction: column; align-items: center; gap: 18px; }

.zoom-row { display: flex; gap: 6px; }
.zoom-row .btn { min-height: 34px; padding: 0 12px; }

/* The sheet itself: workbook units, workbook look. */
.sheet {
  border-collapse: collapse;
  table-layout: fixed;
  background: #fff;
  font-family: 'Roboto Condensed', 'Aptos Narrow', Arial Narrow, Arial, sans-serif;
  color: #000;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}
.sheet td {
  border: 1px solid #000;
  padding: 1px 3px;
  vertical-align: middle;
  font-size: 13.33px;                    /* 10 pt */
  overflow: hidden;
  word-break: break-word;
}
.sheet .hd { background: #c0c0c0; text-align: center; font-size: 14.67px; } /* 11 pt */
.sheet .hd.strong { font-weight: 700; }
.sheet .hd .l1, .sheet .hd .l2 { display: block; line-height: 1.12; }
.sheet .r-title .hd { border-top-width: 2px; }
.sheet .r-title .proj { font-size: 17.33px; font-weight: 700; }   /* 13 pt */
.sheet .r-title .logo { vertical-align: top; padding: 3px; }
.sheet .r-title .logo img { max-width: 100%; max-height: 100%; display: block; margin: 0 auto; }
.sheet .r-hdr td { border-bottom-width: 1px; }
.sheet tr.r-hdr:last-of-type td { border-bottom-width: 2px; }

.sheet .r-spacer td { border: 0; background: #fff; }

.sheet .no { background: #c0c0c0; font-weight: 700; text-align: center; font-size: 14.67px; }
.sheet .desc { text-align: left; }
.sheet .m { text-align: left; }
.sheet .q { text-align: right; }
.sheet .u { text-align: left; }
.sheet .ph { text-align: center; padding: 2px; }
.sheet .ph img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; margin: 0 auto; }

/* Block outlines: medium top on the first row, medium bottom on the last. */
.sheet tr.block-start > td { border-top-width: 2px; }
.sheet tr.block-end > td { border-bottom-width: 2px; }
.sheet tr.r-data > td:first-child { border-left-width: 2px; }
.sheet tr.r-data > td:last-child { border-right-width: 2px; }
.sheet tr.r-title > td:first-child,
.sheet tr.r-hdr > td:first-child { border-left-width: 2px; }
.sheet tr.r-title > td:last-child,
.sheet tr.r-hdr > td:last-child { border-right-width: 2px; }

/* ------------------------------------------------------------- feedback */

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(14px);
  background: var(--navy); color: #fff;
  padding: 11px 16px; border-radius: 9px; font-size: 14px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .3);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  z-index: 60; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--accent-dark); }

.busy {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(14, 26, 38, .45);
  display: grid; place-items: center;
}
.busy-card {
  background: #fff; border-radius: 11px; padding: 16px 20px;
  display: flex; align-items: center; gap: 12px; font-size: 14.5px; font-weight: 600;
}
.spinner {
  width: 19px; height: 19px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card-title { font-weight: 600; margin-bottom: 8px; }
.spaced { margin-top: 10px; }
.hint { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.hint code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.logo-preview {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; border: 1px solid var(--line-2); border-radius: 8px; background: #fbfcfe;
}
.logo-preview img { max-height: 42px; max-width: 170px; display: block; }

@media (max-width: 560px) {
  .row2 { grid-template-columns: 1fr; }
  .mat-table .c-qty, .mat-table .c-unit { width: 68px; }
  .view { padding-left: 10px; padding-right: 10px; }
}

@media print {
  .appbar, .actionbar, .toast, .busy { display: none !important; }
  .view { padding: 0; max-width: none; }
  .preview-scroll { background: none; padding: 0; }
  .sheet { box-shadow: none; }
  .sheet-pages { gap: 0; }
  .sheet-scaler { transform: none !important; }
}
