/* ============================================================
   SOS Inventory Manager — Design System
   ============================================================ */

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 0.875rem;
    color: #111827;
    background: #f3f4f6;
    min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
img { display: block; max-width: 100%; }

/* ── Layout ──────────────────────────────────────────────── */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Top Nav ─────────────────────────────────────────────── */
.topnav {
    display: flex;
    align-items: center;
    gap: 0.125rem;
    height: 52px;
    background: #111827;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 200;
    flex-shrink: 0;
}
.topnav-brand {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.01em;
    margin-right: 1rem;
    white-space: nowrap;
    text-decoration: none;
}
.topnav-brand:hover { color: #e5e7eb; }

/* Nav group — wraps trigger + dropdown */
.nav-group {
    position: relative;
    display: flex;
    align-items: center;
    align-self: stretch;  /* fills full topnav height */
}
.nav-trigger {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0 0.625rem;
    height: 100%;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #d1d5db;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.1s, color 0.1s;
    user-select: none;
    border: none;
    background: transparent;
    text-decoration: none;
}
.nav-trigger:hover { background: #1f2937; color: #fff; }
.nav-trigger.active { background: #2563eb; color: #fff; }
.nav-trigger.active:hover { background: #1d4ed8; }
.nav-caret {
    font-size: 0.625rem;
    opacity: 0.7;
    margin-left: 0.1rem;
}

/* Dropdown panel */
.nav-dropdown {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 180px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.06);
    padding: 0.375rem 0;
    z-index: 300;
    margin-top: 0;
    transition: opacity 0.12s ease, visibility 0s linear 0.18s;
}
/* Invisible bridge fills the gap between trigger and panel so mouse travel doesn't break hover */
.nav-dropdown::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 0;
    right: 0;
    height: 8px;
}
.nav-group:hover .nav-dropdown,
.nav-group.open  .nav-dropdown {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.1s ease, visibility 0s linear 0s;
}
.nav-dropdown-label {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #9ca3af;
    padding: 0.5rem 0.875rem 0.25rem;
}
.nav-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #374151;
    white-space: nowrap;
    transition: background 0.1s;
    text-decoration: none;
}
.nav-dropdown-item:hover { background: #f3f4f6; color: #111827; }
.nav-dropdown-item.active { color: #2563eb; background: #eff6ff; }
.nav-dropdown-sep {
    height: 1px;
    background: #e5e7eb;
    margin: 0.25rem 0;
}
.nav-dropdown.scrollable {
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

/* Main content */
.main-content {
    flex: 1;
    min-width: 0;
    background: #f3f4f6;
}
.page-body {
    padding: 2rem 2.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* ── Typography ──────────────────────────────────────────── */
.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #111827;
    letter-spacing: -0.02em;
}
.page-subtitle {
    font-size: 0.875rem;
    color: #6b7280;
    margin-top: 0.25rem;
}
.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: #111827;
    margin-bottom: 0.75rem;
}

/* ── Page header ────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #111827;
    letter-spacing: -0.02em;
    margin: 0;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
    background: #fff;
    border-radius: 0.75rem;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}
.card-body { padding: 1.5rem; }
.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header-title { font-weight: 600; color: #111827; }

.stat-card {
    background: #fff;
    border-radius: 0.75rem;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    padding: 1.25rem 1.5rem;
}
.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #111827;
    line-height: 1;
}
.stat-card .stat-label {
    font-size: 0.8125rem;
    color: #6b7280;
    margin-top: 0.375rem;
}

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap {
    background: #fff;
    border-radius: 0.75rem;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
thead th {
    background: #f9fafb;
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}
thead th.text-right { text-align: right; }
tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
    vertical-align: middle;
}
tbody td.text-right { text-align: right; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f9fafb; }
.td-link { color: #2563eb; font-weight: 500; }
.td-link:hover { text-decoration: underline; }
.td-muted { color: #9ca3af; font-size: 0.8125rem; }
.td-mono { font-family: "SF Mono", "Fira Code", monospace; font-size: 0.8125rem; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
    text-decoration: none;
    line-height: 1.25;
    white-space: nowrap;
}
.btn:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}
.btn-primary {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-primary:active { background: #1e40af; }

.btn-secondary {
    background: #fff;
    color: #374151;
    border-color: #d1d5db;
}
.btn-secondary:hover { background: #f9fafb; border-color: #9ca3af; }

.btn-danger {
    background: #dc2626;
    color: #fff;
    border-color: #dc2626;
}
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }

.btn-ghost {
    background: transparent;
    color: #6b7280;
    border-color: transparent;
}
.btn-ghost:hover { background: #f3f4f6; color: #111827; }

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

/* ── Form Elements ───────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}
.label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #374151;
}
.label-required::after {
    content: " *";
    color: #ef4444;
}
.input {
    display: block;
    width: 100%;
    padding: 0.5625rem 0.75rem;
    font-size: 0.875rem;
    color: #111827;
    background: #fff;
    border: 1.5px solid #d1d5db;
    border-radius: 0.5rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
    line-height: 1.5;
}
.input:hover { border-color: #9ca3af; }
.input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.input::placeholder { color: #9ca3af; }
.input[disabled] { background: #f3f4f6; color: #9ca3af; cursor: not-allowed; }
select.input { cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; padding-right: 2.25rem; -webkit-appearance: none; appearance: none; }
textarea.input { resize: vertical; min-height: 80px; }
.input-hint { font-size: 0.8125rem; color: #6b7280; margin-top: 0.25rem; }
.input-error { border-color: #ef4444 !important; }
.input-error:focus { box-shadow: 0 0 0 3px rgba(239,68,68,0.12) !important; }

/* Form sections */
.form-section {
    padding-top: 1.25rem;
    margin-top: 1.25rem;
    border-top: 1px solid #e5e7eb;
}
.form-section:first-child,
.form-section:first-of-type {
    padding-top: 0;
    margin-top: 0;
    border-top: none;
}
.form-section-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 1rem;
}

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.grid-stat { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.1875rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1;
}
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-gray   { background: #f3f4f6; color: #4b5563; }
.badge-purple { background: #ede9fe; color: #6d28d9; }

/* ── Flash Messages ──────────────────────────────────────── */
.flash {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
    border: 1px solid transparent;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}
.flash-success { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.flash-error   { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.flash-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }

/* ── Utility ─────────────────────────────────────────────── */
.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-2  { gap: 0.5rem; }
.gap-3  { gap: 0.75rem; }
.gap-4  { gap: 1rem; }
.gap-6  { gap: 1.5rem; }
.mt-1   { margin-top: 0.25rem; }
.mt-2   { margin-top: 0.5rem; }
.mt-3   { margin-top: 0.75rem; }
.mt-4   { margin-top: 1rem; }
.mt-6   { margin-top: 1.5rem; }
.mt-8   { margin-top: 2rem; }
.mb-1   { margin-bottom: 0.25rem; }
.mb-2   { margin-bottom: 0.5rem; }
.mb-3   { margin-bottom: 0.75rem; }
.mb-4   { margin-bottom: 1rem; }
.mb-6   { margin-bottom: 1.5rem; }
.mb-8   { margin-bottom: 2rem; }
.p-4    { padding: 1rem; }
.p-6    { padding: 1.5rem; }
.p-8    { padding: 2rem; }
.px-4   { padding-left: 1rem; padding-right: 1rem; }
.py-2   { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.text-sm    { font-size: 0.875rem; }
.text-xs    { font-size: 0.75rem; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold  { font-weight: 700; }
.text-gray  { color: #6b7280; }
.text-muted { color: #9ca3af; }
.text-red   { color: #dc2626; }
.text-green { color: #16a34a; }
.text-blue  { color: #2563eb; }
.text-link  { color: #2563eb; }
.text-link:hover { text-decoration: underline; }
.truncate   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full     { width: 100%; }
.max-w-xl   { max-width: 36rem; }
.max-w-2xl  { max-width: 42rem; }
.max-w-3xl  { max-width: 48rem; }
.space-y > * + * { margin-top: 1.25rem; }
.form-body > * + * { margin-top: 1.25rem; }
.divider    { border: none; border-top: 1px solid #e5e7eb; margin: 1.5rem 0; }
.back-link  { font-size: 0.875rem; color: #2563eb; display: inline-flex; align-items: center; gap: 0.25rem; margin-bottom: 1.5rem; }
.back-link:hover { text-decoration: underline; }

/* ── Pagination ──────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 0.375rem; margin-top: 1.25rem; }
.page-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 2rem; height: 2rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    border: 1px solid #e5e7eb;
    background: #fff;
    color: #374151;
    transition: background 0.1s;
}
.page-btn:hover  { background: #f3f4f6; }
.page-btn.active { background: #2563eb; color: #fff; border-color: #2563eb; }

/* ── Empty States ────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: #9ca3af;
}
.empty-state p { margin-top: 0.5rem; font-size: 0.875rem; }

/* ── Calendar ───────────────────────────────────────────── */
.cal-nav {
    display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem;
}
.cal-nav h2 { font-size: 1.25rem; font-weight: 600; color: #111827; flex: 1; text-align: center; }
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    overflow: hidden;
}
.cal-dow {
    background: #f9fafb;
    padding: 0.5rem;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    border-bottom: 1px solid #e5e7eb;
    border-right: 1px solid #e5e7eb;
}
.cal-dow:last-child { border-right: none; }
.cal-cell {
    min-height: 80px;
    padding: 0.375rem 0.5rem;
    border-right: 1px solid #e5e7eb;
    border-bottom: 1px solid #e5e7eb;
    background: #fff;
    vertical-align: top;
    position: relative;
}
.cal-cell:nth-child(7n) { border-right: none; }
.cal-cell.other-month { background: #fafafa; }
.cal-cell.other-month .cal-day-num { color: #d1d5db; }
.cal-cell.today { background: #eff6ff; }
.cal-cell.today .cal-day-num {
    background: #2563eb; color: #fff;
    border-radius: 50%; width: 1.5rem; height: 1.5rem;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700;
}
.cal-cell.has-events { cursor: pointer; }
.cal-cell.has-events:hover { background: #f0f9ff; }
.cal-cell.selected { outline: 2px solid #2563eb; outline-offset: -2px; }
.cal-day-num {
    font-size: 0.8rem; font-weight: 500; color: #374151;
    display: inline-block; width: 1.5rem; height: 1.5rem;
    line-height: 1.5rem; text-align: center;
}
.cal-dots { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 3px; }
.cal-dot {
    width: 7px; height: 7px; border-radius: 50%;
    flex-shrink: 0;
}
.cal-dot-invoice  { background: #dc2626; }
.cal-dot-estimate { background: #d97706; }
.cal-dot-po       { background: #2563eb; }
.cal-dot-shipment { background: #059669; }
.cal-dot-return   { background: #7c3aed; }
.cal-dot-receipt  { background: #0891b2; }
.cal-legend {
    display: flex; flex-wrap: wrap; gap: 0.75rem;
    margin: 0.75rem 0 1.5rem;
    font-size: 0.8rem; color: #4b5563;
}
.cal-legend-item { display: flex; align-items: center; gap: 0.35rem; }
.cal-event-section { margin-bottom: 1.25rem; }
.cal-event-section h3 {
    font-size: 0.875rem; font-weight: 600; color: #374151;
    margin-bottom: 0.5rem; padding-bottom: 0.25rem;
    border-bottom: 1px solid #e5e7eb;
}
.cal-event-row {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.4rem 0.5rem; border-radius: 0.375rem;
    font-size: 0.85rem; color: #374151;
    margin-bottom: 2px;
}
.cal-event-row:hover { background: #f9fafb; }
.cal-event-row a { color: inherit; text-decoration: none; flex: 1; }
.cal-event-row a:hover { color: #2563eb; text-decoration: underline; }
.cal-event-type {
    font-size: 0.7rem; font-weight: 600; padding: 0.15rem 0.45rem;
    border-radius: 0.25rem; color: #fff; white-space: nowrap;
}
.cal-event-type.invoice  { background: #dc2626; }
.cal-event-type.estimate { background: #d97706; }
.cal-event-type.po       { background: #2563eb; }
.cal-event-type.shipment { background: #059669; }
.cal-event-type.return   { background: #7c3aed; }
.cal-event-type.receipt  { background: #0891b2; }
.cal-empty { color: #9ca3af; font-size: 0.875rem; text-align: center; padding: 2rem; }

/* ── Upcoming / Activity ─────────────────────────────────── */
.upcoming-row {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.5rem 0.75rem; border-radius: 0.375rem;
    border-left: 3px solid #e5e7eb;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
}
.upcoming-row:hover { background: #f9fafb; }
.upcoming-row a { color: #374151; text-decoration: none; font-weight: 500; }
.upcoming-row a:hover { color: #2563eb; text-decoration: underline; }
.upcoming-row .uc-date { font-size: 0.75rem; color: #9ca3af; white-space: nowrap; }
.upcoming-row .uc-sub  { font-size: 0.75rem; color: #6b7280; }
.upcoming-row.type-invoice  { border-color: #dc2626; }
.upcoming-row.type-estimate { border-color: #d97706; }
.upcoming-row.type-po       { border-color: #2563eb; }
.upcoming-row.type-shipment { border-color: #059669; }
.upcoming-row.type-return   { border-color: #7c3aed; }
.upcoming-row.type-receipt  { border-color: #0891b2; }
.overdue-badge {
    font-size: 0.7rem; font-weight: 600; padding: 0.1rem 0.4rem;
    border-radius: 0.25rem; background: #fef2f2; color: #dc2626;
    border: 1px solid #fecaca;
}

/* ── Settings Dashboard ─────────────────────────────────── */
.settings-list { display: flex; flex-direction: column; gap: 0; margin-top: 0.25rem; }
.settings-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.55rem 0.75rem; border-radius: 0.375rem;
    color: #111827; transition: background 0.1s;
    gap: 0.75rem;
}
.settings-row:hover { background: #f3f4f6; }
.settings-row span:first-child { font-size: 0.875rem; }
.settings-count {
    font-size: 0.75rem; font-weight: 600; color: #6b7280;
    background: #f3f4f6; border-radius: 9999px;
    padding: 0.1rem 0.55rem; white-space: nowrap;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .topnav { gap: 0; padding: 0 0.75rem; }
    .nav-trigger { padding: 0.375rem 0.4rem; font-size: 0.75rem; }
    .topnav-brand { margin-right: 0.5rem; font-size: 0.875rem; }
    .page-body { padding: 1rem; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
