:root {
    --bg: #f6f5f3;
    --card: #ffffff;
    --ink: #2b2724;
    --muted: #8a837c;
    --line: #e7e3de;
    --accent: #b5651d;      /* warm handmade/terracotta */
    --accent-dark: #8f4f16;
    --ok: #2e7d4f;
    --warn: #b8860b;
    --danger: #c0392b;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

a { color: var(--accent-dark); }

/* Top bar */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; padding: 14px 0; }
.brand a { font-weight: 700; font-size: 18px; text-decoration: none; color: var(--ink); }
.brand span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
    padding: 10px 14px;
    text-decoration: none;
    color: var(--muted);
    border-radius: 8px;
    font-weight: 500;
}
.topbar nav a:hover { background: var(--bg); color: var(--ink); }
.topbar nav a.active { color: var(--accent-dark); background: #f3e7d9; }

/* Layout */
.container { max-width: 1080px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 16px; }
.card h3 { font-size: 14px; margin: 18px 0 8px; }

/* Forms */
.stack > * + * { margin-top: 14px; }
label { display: block; font-size: 13px; font-weight: 600; color: #555; }
input, select, textarea {
    width: 100%;
    margin-top: 4px;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    /* Match the Order received field everywhere: same family/size/weight,
       regardless of whether the control sits inside a <label>. */
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    background: #fff;
    color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #e3c9a8; border-color: var(--accent); }
textarea { resize: vertical; }

/* Remove the up/down spinner arrows from every number input. */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
.row { display: flex; gap: 12px; flex-wrap: nowrap; }
.row > * { flex: 1; min-width: 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin: 0; }
fieldset legend { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 6px; }
fieldset > * + * { margin-top: 12px; }
.actions { display: flex; gap: 10px; align-items: center; }
.field { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.field-label { font-size: 13px; font-weight: 600; color: #555; }
.radio-row { display: flex; gap: 18px; }
.radio-row .inline { display: flex; align-items: center; gap: 6px; font-weight: 500; color: var(--ink); }
.radio-row .inline input { width: auto; margin: 0; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 9px 16px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--danger); border-color: #e6c4bf; }
.btn.danger:hover { background: #fbecea; }
.btn.small { padding: 5px 10px; font-size: 13px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 24px; }
@media (max-width: 820px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; }
.stat .num { font-size: 24px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat.alert { border-color: #e6c4bf; background: #fdf2f0; }
.stat.alert .num { color: var(--danger); }
.stat.warn { border-color: #ecdcb3; background: #fdf8ec; }
.stat.warn .num { color: var(--warn); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
.orders-table th, .orders-table td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); font-size: 14px; }
.orders-table th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.orders-table tbody tr { cursor: pointer; }
.orders-table tbody tr:hover { background: #faf7f3; }
.mono, .mono * { font-variant-numeric: tabular-nums; }
.num { text-align: right; }

.items-table { margin-top: 12px; }
.items-table th, .items-table td { padding: 6px 6px; border-bottom: 1px solid var(--line); font-size: 13px; }
.items-table th { font-size: 11px; text-transform: uppercase; color: var(--muted); }
.items-table input { margin-top: 0; }
.items-table td.num input { text-align: right; }
.items-table th.num { text-align: right; }

/* Full-width products table: the Product column takes all remaining space so
   long product names stay fully visible; the rest are sized to their content. */
#items-table { width: 100%; table-layout: fixed; }
#items-table input { width: 100%; box-sizing: border-box; }
#items-table th.num, #items-table td.num { width: 120px; }
#items-table th:last-child, #items-table td:last-child { width: 44px; text-align: center; }

/* Filters */
.filters { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1; min-width: 200px; margin-top: 0; }
.filters select { width: auto; margin-top: 0; }

/* Badges & pills */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.overdue { background: #fbecea; color: var(--danger); }
.badge.due-today { background: #fdf2e3; color: var(--accent-dark); }
.badge.due-soon { background: #fdf8ec; color: var(--warn); }
.badge.ok { background: #eaf5ee; color: var(--ok); }
.badge.done { background: #eee; color: var(--muted); }

.status-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef0f2; color: #4a5258; }
.status-new { background: #e7eefb; color: #2f5bbf; }
.status-confirmed { background: #e3f1ff; color: #1f6fb0; }
.status-in-progress { background: #fdf2e3; color: var(--accent-dark); }
.status-awaiting-supplies { background: #fdf8ec; color: var(--warn); }
.status-ready { background: #eaf5ee; color: var(--ok); }
.status-shipped { background: #e8f5e9; color: #2e7d32; }
.status-completed { background: #eef0f2; color: #555; }
.status-cancelled { background: #fbecea; color: var(--danger); }

/* Autocomplete */
.autocomplete { position: relative; }
.suggestions {
    list-style: none; margin: 4px 0 0; padding: 4px;
    border: 1px solid var(--line); border-radius: 8px; background: #fff;
    box-shadow: var(--shadow); position: absolute; left: 0; right: 0; z-index: 20; max-height: 280px; overflow: auto;
}
.suggestions li { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.suggestions li:hover { background: #f3e7d9; }

/* Products list */
.product-list { display: flex; flex-direction: column; gap: 12px; }
.product-item { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.product-main { display: flex; justify-content: space-between; align-items: baseline; }
.product-main .price { font-weight: 700; color: var(--accent-dark); }
.product-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.product-actions form { display: inline; }

/* Clients */
.client-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.client-card { margin-bottom: 0; }
.client-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.client-top strong { font-size: 16px; }
.order-count { background: #f3e7d9; color: var(--accent-dark); font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.client-details { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 12px; }
.client-details dt { color: var(--muted); font-size: 12px; }
.client-details dd { margin: 0; font-size: 13px; word-break: break-word; }
.client-actions { display: flex; gap: 8px; align-items: center; }
.client-actions form { display: inline; }

/* Payment */
.summary dd.balance-due { color: var(--danger); }

/* Prominent promised date/time at the top of the Status & Deadline card. */
.promised-line { font-size: 20px; font-weight: 700; margin: 0 0 12px; color: var(--ink); }

/* Payment card: deposit, payments table, paid-in-full stamp */
.payment-card .field { margin-bottom: 14px; }
.deposit-entry { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; margin-bottom: 14px; }
.deposit-entry label.inline { display: flex; align-items: center; gap: 6px; margin: 0; white-space: nowrap; }
.deposit-entry #deposit-amount-input { width: 90px; margin: 0; }
.deposit-entry .btn { white-space: nowrap; }
/* Match the height of the deposit input and the Deposit received button. */
.deposit-entry #deposit-amount-input,
.deposit-entry .btn { height: 40px; box-sizing: border-box; }
.deposit-entry .btn { display: inline-flex; align-items: center; padding-top: 0; padding-bottom: 0; }
.deposit-label { margin-bottom: 14px; padding: 8px 12px; background: #eaf5ee; color: var(--ok); border-radius: 8px; font-weight: 600; }
/* Balance Due banner at the top: same shape as the deposit label, red tone. */
.balance-due-box { margin-bottom: 14px; padding: 8px 12px; background: #fbecea; color: var(--danger); border-radius: 8px; font-weight: 600; }
.add-payment-row { display: flex; align-items: stretch; gap: 8px; flex-wrap: nowrap; margin-bottom: 6px; }
.add-payment-row input, .add-payment-row select { margin: 0; min-width: 0; }
.add-payment-row #new-payment-date { flex: 0 0 auto; width: auto; }
.add-payment-row #new-payment-amount { flex: 0 0 90px; width: 90px; text-align: right; }
.add-payment-row #new-payment-method { flex: 1 1 auto; width: auto; }
.add-payment-row .btn { flex: 0 0 auto; white-space: nowrap; }
/* Match the height of every control on the add-payment row. */
.add-payment-row input,
.add-payment-row select,
.add-payment-row .btn { height: 40px; box-sizing: border-box; }
.add-payment-row .btn { display: inline-flex; align-items: center; padding-top: 0; padding-bottom: 0; }
.payments-table { width: 100%; }
.payments-table td.num { white-space: nowrap; }
.payments-table .remove-payment { padding: 2px 8px; }

/* Paid-in-full: hide the management UI, show the stamp */
.paid-stamp { display: none; margin: 6px 0 14px; padding: 14px; text-align: center; font-size: 22px; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; color: var(--ok); border: 3px solid var(--ok); border-radius: 10px; opacity: 0.9; }
.payment-card.paid-in-full .paid-stamp { display: block; }
.payment-card.paid-in-full #deposit-area,
.payment-card.paid-in-full #payment-manage,
.payment-card.paid-in-full .balance-due-box { display: none; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto; }
.modal-overlay[hidden] { display: none; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25); max-height: calc(100vh - 80px); display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.modal-close:hover { color: var(--ink); }
.modal-body { padding: 20px; overflow-y: auto; }

/* Misc */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.summary { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 14px 0 0; }
.summary dt { color: var(--muted); font-size: 13px; }
.summary dd { margin: 0; font-weight: 600; text-align: right; }
.mini-orders { list-style: none; margin: 0; padding: 0; }
.mini-orders li a { display: flex; gap: 12px; align-items: center; padding: 8px 6px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.mini-orders li a:hover { background: #faf7f3; }
.message-log { list-style: none; margin: 8px 0 0; padding: 0; }
.message-log li { border-top: 1px solid var(--line); padding: 10px 0; }
.msg-head { display: flex; justify-content: space-between; gap: 10px; }
.flash { background: #eaf5ee; border: 1px solid #c6e4d2; color: var(--ok); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.alert-box { background: #fbecea; border: 1px solid #e6c4bf; color: #8a2b1f; padding: 10px 14px; border-radius: 8px; font-size: 13px; margin: 12px 0; line-height: 1.45; }
.alert-box strong { color: var(--danger); }
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 30px; }
.footer .reset-note { color: var(--accent-dark); }
.footer .promo {
    max-width: 620px; margin: 30px auto 0; padding: 26px 28px;
    background: linear-gradient(180deg, #fff 0%, #fbf3ea 100%);
    border: 1px solid var(--accent); border-radius: var(--radius);
    box-shadow: 0 6px 20px rgba(143, 79, 22, .10);
    color: var(--ink); line-height: 1.55; text-align: center;
}
.footer .promo h3 { margin: 0 0 12px; color: var(--accent-dark); font-size: 19px; }
.footer .promo p { margin: 8px 0; font-size: 14px; }
.footer .promo .cta {
    display: inline-block; margin-top: 16px; padding: 11px 22px;
    background: var(--accent); color: #fff; font-weight: 700; font-size: 14px;
    border-radius: 8px; text-decoration: none;
}
.footer .promo .cta:hover { background: var(--accent-dark); }
.footer .promo .credit { color: var(--muted); font-size: 13px; }

/* Lets wide tables scroll sideways instead of overflowing on small screens. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---- Mobile ---- */
@media (max-width: 640px) {
    .container { padding: 16px; }

    /* Top bar: let the brand + nav stack and wrap instead of overflowing. */
    .topbar { padding: 0 16px; }
    .topbar nav { flex-wrap: wrap; }

    /* Page header: title on top, action buttons wrap beneath it. */
    .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
    .page-head h1 { font-size: 20px; }
    .page-head .actions { display: flex; flex-wrap: wrap; gap: 8px; }

    /* Stack price/prep/qty style rows on very narrow screens. */
    .row { flex-wrap: wrap; }
    .row > * { flex: 1 1 100%; }

    /* Filters span the full width. */
    .filters input[type=search] { flex: 1 1 100%; }

    /* Order line-item table: tighter columns so it fits a phone. */
    #items-table th.num, #items-table td.num { width: 64px; }
    #items-table th:last-child, #items-table td:last-child { width: 32px; }
    .items-table th, .items-table td { padding: 5px 4px; }

    /* Add-payment row may wrap; method takes its own line. */
    .add-payment-row { flex-wrap: wrap; }
    .add-payment-row #new-payment-method { flex: 1 1 100%; }

    /* Smaller promised headline. */
    .promised-line { font-size: 18px; }

    /* Modal hugs the screen edges. */
    .modal-overlay { padding: 16px; }
    .modal { max-height: calc(100vh - 32px); }
}
