/*
 * Component layer on top of Tailwind.
 *
 * Design intent: this is a working tool for someone standing behind a counter,
 * not a marketing dashboard. That means:
 *   - warm neutrals (stone) rather than cold grey, one deep green accent
 *   - 1px borders instead of shadows; shadows only for things that float
 *   - 8px radii — soft, not pill-shaped
 *   - one visually dominant action per screen, everything else quieter
 *   - no gradients, no decorative charts, no icon soup
 *
 * Only patterns repeated across several screens live here. One-off styling
 * stays inline as utility classes.
 */

:root {
    --ink:        #1c1917; /* stone-900 */
    --ink-soft:   #44403c; /* stone-700 */
    --muted:      #78716c; /* stone-500 */
    --line:       #e7e5e4; /* stone-200 */
    --line-soft:  #f5f5f4; /* stone-100 */
    --surface:    #ffffff;
    --canvas:     #fafaf9; /* stone-50 */
    --accent:     #166534; /* green-800 */
    --accent-ink: #14532d; /* green-900 */
}

/* ---------------------------------------------------------------- Base ---- */

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

body {
    background-color: var(--canvas);
    color: var(--ink);
    font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
    -webkit-font-smoothing: antialiased;
}

/* Numeric columns must line up; tabular figures are non-negotiable in a
   stock table where the eye scans down a column of quantities. */
.tnum {
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum';
}

h1, h2, h3 {
    letter-spacing: -0.02em;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* -------------------------------------------------------------- Buttons ---- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border-radius: 0.5rem;
    border: 1px solid transparent;
    padding: 0.5rem 0.875rem;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.25rem;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-ink); }

.btn-secondary {
    background: var(--surface);
    color: var(--ink-soft);
    border-color: var(--line);
}
.btn-secondary:hover:not(:disabled) { background: var(--line-soft); }

.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--line-soft); color: var(--ink); }

.btn-danger { background: #fff; color: #b91c1c; border-color: #fecaca; }
.btn-danger:hover:not(:disabled) { background: #fef2f2; }

.btn-sm { padding: 0.3125rem 0.625rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.8125rem 1.25rem; font-size: 0.9375rem; border-radius: 0.625rem; }

/* The one action that must dominate every dashboard: today's purchase order. */
.btn-hero {
    background: var(--accent);
    color: #fff;
    border-radius: 0.75rem;
    padding: 1rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    width: 100%;
}
.btn-hero:hover { background: var(--accent-ink); }

@media (min-width: 640px) {
    .btn-hero { width: auto; }
}

/* --------------------------------------------------------------- Cards ---- */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 0.625rem;
}

.card-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--line);
}

.card-title {
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

/* --------------------------------------------------------------- Forms ---- */

.label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--ink-soft);
    margin-bottom: 0.375rem;
}

.hint {
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--muted);
    margin-top: 0.375rem;
}

.input,
.select,
.textarea {
    display: block;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 0.5rem;
    background: var(--surface);
    padding: 0.5625rem 0.75rem;
    font-size: 0.9375rem;
    color: var(--ink);
}

.input::placeholder, .textarea::placeholder { color: #a8a29e; }

.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(22, 101, 52, .1);
}

.input-error { border-color: #ef4444; }
.input-error:focus { box-shadow: 0 0 0 3px rgba(239, 68, 68, .12); }

.error-text { font-size: 0.75rem; color: #b91c1c; margin-top: 0.25rem; }

/* Numeric entry on a phone: big enough to hit with a thumb, right-aligned so
   the digits line up while counting down a shelf. */
.input-qty {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: 1rem;
    font-weight: 600;
    padding: 0.625rem 0.75rem;
}

/* -------------------------------------------------------------- Badges ---- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3125rem;
    border-radius: 999px;
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.25rem;
    white-space: nowrap;
}

.badge-green  { background: #f0fdf4; color: #15803d; box-shadow: inset 0 0 0 1px #bbf7d0; }
.badge-amber  { background: #fffbeb; color: #b45309; box-shadow: inset 0 0 0 1px #fde68a; }
.badge-red    { background: #fef2f2; color: #b91c1c; box-shadow: inset 0 0 0 1px #fecaca; }
.badge-blue   { background: #eff6ff; color: #1d4ed8; box-shadow: inset 0 0 0 1px #bfdbfe; }
.badge-slate  { background: #f5f5f4; color: #57534e; box-shadow: inset 0 0 0 1px #e7e5e4; }

.badge-dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }

/* --------------------------------------------------------------- Table ---- */

.table { width: 100%; border-collapse: collapse; }

.table thead th {
    padding: 0.625rem 0.75rem;
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.table tbody td {
    padding: 0.6875rem 0.75rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fcfcfb; }

.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* A row that needs action today gets a red spine on the left edge — visible
   while scanning at arm's length, invisible when everything is fine. */
.row-urgent { box-shadow: inset 3px 0 0 0 #dc2626; }
.row-warn   { box-shadow: inset 3px 0 0 0 #f59e0b; }

/* ------------------------------------------------------- Navigation ---- */

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.6875rem;
    border-radius: 0.5rem;
    padding: 0.5rem 0.6875rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ink-soft);
}

.nav-link:hover { background: var(--line-soft); color: var(--ink); }

.nav-link-active {
    background: #f0fdf4;
    color: var(--accent-ink);
    font-weight: 600;
}

.nav-link-active svg { color: var(--accent); }

/* Bottom tab bar: the primary navigation on a phone, because that is where a
   thumb is. Desktop uses the sidebar instead. */
.tabbar {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    background: rgba(255, 255, 255, .95);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
}

.tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
    padding: 0.5rem 0.25rem 0.4375rem;
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--muted);
}

.tabbar a[aria-current="page"] { color: var(--accent); }

/* ------------------------------------------------------------- Utility ---- */

.divide-line > * + * { border-top: 1px solid var(--line-soft); }

.stat-value {
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--muted);
}

/* Horizontal bar used in the reports screen. A bar is a length, not a picture:
   no axes, no gridlines, no legend. */
.bar {
    height: 0.5rem;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
}
.bar > span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--accent);
}

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.sticky-actions {
    position: sticky;
    bottom: 0;
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--line);
    padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
}

[x-cloak], .js-hidden { display: none !important; }

@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
    .card { border-color: #ddd; }
}
