/* ==========================================================================
   Precision Interior Products — Purchase Order Panel
   REPLACES the app.css generated by the Visual Studio template.
   ========================================================================== */

:root {
    --nav-bg: #0b1a3a;
    --nav-bg-2: #0f2148;
    --nav-active: #1b2f5c;
    --nav-text: #c9d4ec;
    --bg: #f4f6fb;
    --card: #ffffff;
    --border: #e6eaf2;
    --border-strong: #d5dbe7;
    --text: #0f1a33;
    --text-dim: #5c6b88;
    --text-mute: #8a97b5;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --blue-soft: #e3edff;
    --blue-ink: #1e40af;
    --amber-soft: #fde8c8;
    --amber-ink: #8a5a12;
    --green-soft: #d3f2df;
    --green-ink: #116a3a;
    --red-soft: #fbdcdc;
    --red-ink: #9c1f1f;
    --gray-soft: #e8ecf3;
    --gray-ink: #495467;
    --shadow-sm: 0 1px 2px rgba(15,26,51,.06);
    --shadow-lg: 0 20px 50px rgba(15,26,51,.18);
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    font-family: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }

.muted { color: var(--text-dim); }

/* ---------- LAYOUT ---------- */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
    width: 236px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--nav-bg) 0%, var(--nav-bg-2) 100%);
    color: var(--nav-text);
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.brand {
    padding: 22px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,.05);
}

.brand .logo {
    width: 38px; height: 38px; flex-shrink: 0;
    background: linear-gradient(135deg, #3b82f6, #60a5fa 60%, #93c5fd);
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(59,130,246,.35);
}

.brand .name {
    font-weight: 800; letter-spacing: .5px; font-size: 15px; line-height: 1.15; color: #fff;
}

.brand .name small {
    display: block; font-size: 9px; letter-spacing: 2.5px;
    font-weight: 600; color: #9db3e0; margin-top: 2px;
}

.nav-menu { padding: 14px 12px; flex: 1; overflow-y: auto; }

.nav-menu .nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px; border-radius: 8px;
    color: var(--nav-text); text-decoration: none;
    font-weight: 500; font-size: 14px; margin-bottom: 2px;
    transition: background .15s ease, color .15s ease;
}

.nav-menu .nav-link:hover { background: rgba(255,255,255,.05); color: #fff; }

.nav-menu .nav-link.active {
    background: var(--nav-active); color: #fff;
    box-shadow: inset 3px 0 0 var(--primary);
}

.nav-menu .nav-link svg { width: 18px; height: 18px; stroke-width: 1.8; flex-shrink: 0; }

.sidebar-foot {
    padding: 14px 20px;
    border-top: 1px solid rgba(255,255,255,.05);
    font-size: 12px;
    color: #8a97b5;
}

.sidebar-foot a { color: #9db3e0; text-decoration: none; }
.sidebar-foot a:hover { text-decoration: underline; }

.sidebar-foot .who { font-weight: 600; color: #e6ecf8; margin-bottom: 6px; }
.sidebar-foot .foot-links { display: flex; gap: 12px; align-items: center; }
.sidebar-foot form { display: inline; margin: 0; }

/* The sign-out control has to be a form button (it POSTs), but it should read as
   the link next to it. */
.sidebar-foot .linkish {
    background: none; border: 0; padding: 0;
    color: #9db3e0; font: inherit; font-size: 12px; cursor: pointer;
}

.sidebar-foot .linkish:hover { text-decoration: underline; }

.main-area { flex: 1; min-width: 0; height: 100vh; overflow-y: auto; padding: 0 32px 40px; }

.page-head {
    padding: 22px 0;
    display: flex; align-items: center; justify-content: space-between;
}

.page-head h1 {
    margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.3px;
}

/* ---------- BUTTONS ---------- */
.primary-btn {
    background: var(--primary); color: #fff; border: none; border-radius: 10px;
    padding: 11px 20px; font-weight: 600; font-size: 14px; cursor: pointer;
    display: inline-flex; align-items: center; gap: 8px;
    box-shadow: 0 4px 12px rgba(37,99,235,.28);
}

.primary-btn:hover:not(:disabled) { background: var(--primary-hover); }
.primary-btn:disabled { opacity: .55; cursor: not-allowed; }
.primary-btn svg { width: 16px; height: 16px; }

.ghost-btn {
    background: #fff; color: var(--text); border: 1px solid var(--border-strong);
    border-radius: 10px; padding: 10px 18px; font-weight: 500; font-size: 13px; cursor: pointer;
}

.ghost-btn:hover:not(:disabled) { background: #f7f9fc; }
.ghost-btn:disabled { opacity: .55; cursor: not-allowed; }

.icon-x {
    background: transparent; border: none; color: var(--text-dim);
    font-size: 24px; line-height: 1; cursor: pointer;
    width: 32px; height: 32px; border-radius: 8px;
}

.icon-x:hover { background: #f0f3f9; color: var(--text); }

/* ---------- STAT TILES ---------- */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 22px; }

.stat {
    background: var(--card); border: 1px solid var(--border); border-radius: 14px;
    padding: 20px 22px; display: flex; align-items: center; gap: 16px; box-shadow: var(--shadow-sm);
}

.stat .stat-ico {
    width: 52px; height: 52px; border-radius: 50%;
    display: grid; place-items: center; flex-shrink: 0;
}

.stat .stat-ico svg { width: 22px; height: 22px; }
.stat .stat-label { font-size: 13px; color: var(--text-dim); margin-bottom: 2px; font-weight: 500; }
.stat .stat-value { font-size: 26px; font-weight: 700; color: var(--primary); line-height: 1; }

.stat.open .stat-ico { background: #e3edff; color: #2563eb; }
.stat.ship .stat-ico { background: #e0efff; color: #1e6ac9; }
.stat.back .stat-ico { background: #fde8c8; color: #d97706; }
.stat.back .stat-value { color: #d97706; }
.stat.recv .stat-ico { background: #d3f2df; color: #116a3a; }
.stat.recv .stat-value { color: #116a3a; }

/* ---------- PANEL + TABLE ---------- */
.panel {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 14px; box-shadow: var(--shadow-sm); overflow: hidden;
}

.panel-tools {
    padding: 16px 20px; display: flex; align-items: center; gap: 12px;
    flex-wrap: wrap; border-bottom: 1px solid var(--border);
}

.search { flex: 1; min-width: 240px; position: relative; }

.search svg {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    width: 16px; height: 16px; color: var(--text-mute);
}

.search input {
    width: 100%; padding: 10px 12px 10px 36px; border-radius: 10px;
    border: 1px solid var(--border-strong); font-size: 13px;
    color: var(--text); background: #fff; outline: none;
}

.search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

.select-wrap {
    display: inline-flex; align-items: center;
    border: 1px solid var(--border-strong); border-radius: 10px;
    background: #fff; padding: 0 6px;
}

.select-wrap select {
    border: none; background: transparent; font: inherit; font-size: 13px;
    color: var(--text); padding: 10px 8px; outline: none; cursor: pointer;
}

.checkbox {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 13px; color: var(--text-dim); cursor: pointer; user-select: none;
}

.table-wrap { overflow-x: auto; }

table.po { width: 100%; border-collapse: collapse; font-size: 13.5px; }

table.po thead th {
    text-align: left; font-weight: 600; color: var(--text-dim);
    padding: 14px 12px; font-size: 12.5px;
    border-bottom: 1px solid var(--border); background: #fafbfd; white-space: nowrap;
}

table.po tbody td {
    padding: 15px 12px; border-bottom: 1px solid var(--border);
    color: var(--text); white-space: nowrap;
}

table.po tbody tr:hover { background: #f7f9fc; }
table.po td:first-child, table.po th:first-child { padding-left: 20px; }
table.po td:last-child, table.po th:last-child { padding-right: 20px; }
table.po td.mono { font-variant-numeric: tabular-nums; color: var(--text-dim); font-weight: 500; }
table.po td.po-num { font-weight: 600; }
table.po td.empty { padding: 40px; text-align: center; color: var(--text-mute); }

/* ---------- STATUS PILLS ---------- */
.pill {
    display: inline-flex; align-items: center;
    padding: 4px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 500; white-space: nowrap;
}

.pill.blue  { background: var(--blue-soft);  color: var(--blue-ink); }
.pill.amber { background: var(--amber-soft); color: var(--amber-ink); }
.pill.green { background: var(--green-soft); color: var(--green-ink); }
.pill.red   { background: var(--red-soft);   color: var(--red-ink); }
.pill.gray  { background: var(--gray-soft);  color: var(--gray-ink); }

/* ---------- PAGINATION ---------- */
.pager {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 20px; color: var(--text-dim); font-size: 13px;
}

.pager-mid { display: flex; align-items: center; gap: 12px; }

.pg-btn {
    padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border-strong);
    background: #fff; color: var(--text); cursor: pointer; font-weight: 500; font-size: 13px;
}

.pg-btn:hover:not(:disabled) { background: #f7f9fc; }
.pg-btn:disabled { opacity: .45; cursor: not-allowed; }
.pg-current { font-variant-numeric: tabular-nums; }

/* ---------- PO DETAIL ---------- */
.back-link {
    display: inline-block; font-size: 12px; color: var(--text-dim);
    text-decoration: none; margin-bottom: 4px;
}

.back-link:hover { color: var(--primary); }

.detail-title { display: flex; align-items: center; gap: 12px; }

.head-actions { display: flex; align-items: center; gap: 10px; }

/* minmax(0,1fr) rather than 1fr: without it a long unbroken value — a pasted URL,
   a 200-character job name — pushes the main column past the viewport. */
.detail-grid {
    display: grid; grid-template-columns: minmax(0, 1fr) 340px;
    gap: 20px; align-items: start;
}

.detail-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* Same visual tokens as .panel, but a separate class: .panel sets overflow:hidden
   for its edge-to-edge table, which would clip anything that needs to escape. */
.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 14px; box-shadow: var(--shadow-sm);
}

.card-head {
    padding: 14px 20px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}

.card-head h2 { margin: 0; font-size: 14px; font-weight: 700; }
.card-body { padding: 18px 20px; }

.notice {
    padding: 40px 20px; text-align: center; color: var(--text-dim);
}

.notice p { margin: 0 0 16px; }

/* auto-fit gives 3 columns wide, 2 medium and 1 on mobile from one declaration. */
.kv-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px 24px;
}

.kv { min-width: 0; }
.kv.wide { grid-column: 1 / -1; }

.kv-label {
    font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 3px;
}

.kv-value { font-size: 14px; color: var(--text); overflow-wrap: anywhere; }
.kv-value.mono { font-variant-numeric: tabular-nums; }
.kv-value.empty { color: var(--text-mute); }
.kv-value.notes { white-space: pre-wrap; line-height: 1.55; }

.field-hint { margin: 6px 0 0; font-size: 12px; color: var(--text-mute); }

/* The inline note prompt that every status change goes through. */
.confirm-bar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 12px 20px; border-bottom: 1px solid var(--border);
    background: #fafbfd;
}

.confirm-bar .confirm-label { font-size: 13px; font-weight: 600; white-space: nowrap; }

.confirm-bar input {
    flex: 1; min-width: 180px; padding: 9px 12px; border-radius: 8px;
    border: 1px solid var(--border-strong); font: inherit; font-size: 13px;
    color: var(--text); background: #fff; outline: none;
}

.confirm-bar input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

/* ---------- STATUS TIMELINE ---------- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 24px; position: relative; }

.tl-item { position: relative; padding-bottom: 18px; }
.tl-item:last-child { padding-bottom: 0; }

.tl-item::before {
    content: ''; position: absolute; left: -24px; top: 3px;
    width: 11px; height: 11px; border-radius: 50%;
    background: var(--gray-soft); border: 2px solid var(--gray-ink); box-sizing: border-box;
}

/* Rail drawn per item rather than on the <ol>, so no stub hangs past the last dot. */
.tl-item:not(:last-child)::after {
    content: ''; position: absolute; left: -19px; top: 16px; bottom: 0;
    width: 2px; background: var(--border);
}

/* Dot colour comes from PoStatusExtensions.PillClass() — one status-to-colour
   function, two renderings, so the pill and the dot cannot drift apart. */
.tl-item.blue::before  { background: var(--blue-soft);  border-color: var(--blue-ink); }
.tl-item.amber::before { background: var(--amber-soft); border-color: var(--amber-ink); }
.tl-item.green::before { background: var(--green-soft); border-color: var(--green-ink); }
.tl-item.red::before   { background: var(--red-soft);   border-color: var(--red-ink); }
.tl-item.gray::before  { background: var(--gray-soft);  border-color: var(--gray-ink); }

.tl-what { font-size: 13px; font-weight: 600; }
.tl-when { font-size: 12px; color: var(--text-mute); font-variant-numeric: tabular-nums; }
.tl-note { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; white-space: pre-wrap; }

/* ---------- COMMENTS ---------- */
.comment {
    border-left: 2px solid var(--border); padding-left: 12px; margin-bottom: 16px;
}

.comment-head { display: flex; align-items: baseline; gap: 8px; font-size: 12px; }
.comment-who { font-weight: 600; color: var(--text); }
.comment-when { color: var(--text-mute); font-variant-numeric: tabular-nums; }

/* pre-wrap because pasted vendor emails otherwise collapse into one paragraph;
   overflow-wrap because a single pasted tracking URL otherwise widens the card. */
.comment-body {
    font-size: 13.5px; line-height: 1.55; margin-top: 4px;
    white-space: pre-wrap; overflow-wrap: anywhere;
}

.comment-empty { color: var(--text-mute); font-size: 13px; margin: 0 0 16px; }

.comment-new { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.comment-new textarea {
    width: 100%; padding: 10px 12px; border-radius: 8px;
    border: 1px solid var(--border-strong); font: inherit; font-size: 13px;
    color: var(--text); background: #fff; outline: none; resize: vertical; min-height: 70px;
}

.comment-new textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

/* ---------- ATTACHMENTS ---------- */
.file {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 0; border-bottom: 1px solid var(--border);
}

.file:last-child { border-bottom: none; }

.file-ico {
    width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
    background: var(--gray-soft); color: var(--gray-ink);
    display: grid; place-items: center;
}

.file-ico svg { width: 16px; height: 16px; }

.file-main { min-width: 0; }

.file-name {
    color: var(--primary); font-weight: 600; font-size: 13px;
    text-decoration: none; overflow-wrap: anywhere;
}

.file-name:hover { text-decoration: underline; }
.file-meta { font-size: 12px; color: var(--text-mute); margin-top: 2px; }
.file-empty { color: var(--text-mute); font-size: 13px; margin: 0; }

.upload-row {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border);
}

.upload-row input[type=file] { font: inherit; font-size: 12px; max-width: 100%; }
.upload-hint { flex-basis: 100%; margin: 0; font-size: 12px; color: var(--text-mute); }

/* ---------- BARE SHELL (error page) ---------- */
.bare-shell { max-width: 620px; margin: 80px auto; padding: 0 24px; }

/* ---------- ADMIN SCREENS ---------- */
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }

.mini-btn {
    padding: 4px 10px; font-size: 12px; border-radius: 6px; font: inherit; font-size: 12px;
    border: 1px solid var(--border-strong); background: #fff;
    color: var(--text); cursor: pointer; white-space: nowrap;
}

.mini-btn:hover:not(:disabled) { background: #f7f9fc; }
.mini-btn:disabled { opacity: .5; cursor: not-allowed; }
.mini-btn.danger { color: var(--red-ink); border-color: var(--red-soft); }
.mini-btn.danger:hover:not(:disabled) { background: var(--red-soft); }

/* Two-up inside the drawer, for pairs like Name + Code. */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* A checkbox that reads as a field rather than as stray form furniture. */
.field .field-check {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; font-weight: 500; cursor: pointer;
}

.field .field-check input { width: auto; }

/* ---------- CLICKABLE TABLE ROWS ---------- */
table.po tbody tr.row-link { cursor: pointer; }

/* The focusable element is the anchor inside the cell, so surface its focus at
   row level — otherwise keyboard users get a ring around three words of a wide row. */
table.po tbody tr.row-link:focus-within {
    outline: 2px solid var(--primary); outline-offset: -2px;
}

/* ---------- DRAWER ---------- */
.drawer-scrim {
    position: fixed; inset: 0; background: rgba(15,26,51,.28);
    opacity: 0; pointer-events: none; transition: opacity .2s ease; z-index: 40;
}

.drawer-scrim.open { opacity: 1; pointer-events: auto; }

.drawer {
    position: fixed; top: 0; right: 0; height: 100vh; width: 400px; max-width: 96vw;
    background: #fff; box-shadow: var(--shadow-lg);
    transform: translateX(100%); transition: transform .25s ease; z-index: 50;
    display: flex; flex-direction: column;
}

.drawer.open { transform: translateX(0); }

.drawer-head {
    padding: 22px 24px 14px; display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.drawer-head h2 { margin: 0; font-size: 17px; font-weight: 700; }

.drawer-body { padding: 20px 24px; overflow-y: auto; flex: 1; }

.drawer-foot {
    padding: 14px 24px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 10px;
}

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .req { color: #dc2626; }

.field input, .field select, .field textarea {
    width: 100%; padding: 10px 12px; border-radius: 8px;
    border: 1px solid var(--border-strong); font: inherit; font-size: 13px;
    color: var(--text); background: #fff; outline: none;
}

.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.field textarea { resize: vertical; min-height: 78px; }
.field select:disabled { background: #f4f6fb; color: var(--text-mute); }

.form-error {
    background: var(--red-soft); color: var(--red-ink);
    padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px;
}

/* ---------- TOAST ---------- */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: #0f1a33; color: #fff; padding: 11px 18px; border-radius: 10px;
    font-size: 13px; z-index: 60; box-shadow: var(--shadow-lg);
}

/* ---------- BLAZOR ERROR UI (from the template, restyled) ---------- */
#blazor-error-ui {
    background: #fef0c7; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none; left: 0; padding: 14px 20px; position: fixed; width: 100%; z-index: 1000;
}

#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 18px; top: 12px; }

.blazor-error-boundary {
    background: var(--red-soft); color: var(--red-ink);
    padding: 14px 20px; border-radius: 8px; margin: 16px 0;
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 1080px) {
    .stat-row { grid-template-columns: repeat(2, 1fr); }
    .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .sidebar { width: 64px; }
    .brand .name, .nav-menu .nav-link span { display: none; }
    .stat-row { grid-template-columns: 1fr; }
    .main-area { padding: 0 16px 40px; }
}
