:root {
    --bg: #0a0a0f;
    --card-bg: #12121a;
    --surface: #171722;
    --border: #2b2b38;
    --control-border: #747484;
    --text: #f4f4f5;
    --text-sub: #a1a1aa;
    --accent: #4ade80;
    --accent-strong: #15803d;
    --accent-hover: #166534;
    --danger: #f87171;
    --warning: #fbbf24;
    --success: #4ade80;
    --info: #60a5fa;
    --focus: #60a5fa;
    --hover-bg: rgba(255,255,255,0.06);
    --active-bg: rgba(255,255,255,0.1);
    --readonly-bg: #1b1b26;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --sidebar-w: 240px;
    --bottom-nav-h: 60px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    color-scheme: dark;
}

.light {
    --bg: #f5f5f5;
    --card-bg: #ffffff;
    --surface: #f9fafb;
    --border: #d1d5db;
    --control-border: #6b7280;
    --text: #1f2937;
    --text-sub: #4b5563;
    --accent: #15803d;
    --accent-strong: #15803d;
    --accent-hover: #166534;
    --danger: #b91c1c;
    --warning: #92400e;
    --success: #15803d;
    --info: #1d4ed8;
    --focus: #1d4ed8;
    --hover-bg: rgba(31,41,55,0.06);
    --active-bg: rgba(31,41,55,0.1);
    --readonly-bg: #f3f4f6;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    color-scheme: light;
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.modal-open {
    position: fixed;
    width: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

button, input, select, textarea {
    font: inherit;
}

button, a, input, select, textarea {
    -webkit-tap-highlight-color: transparent;
}

button, .btn, a {
    touch-action: manipulation;
}

img, svg, video, canvas {
    max-width: 100%;
}

h1, h2, h3, p, a, td, th, .summary-row, .product-name {
    overflow-wrap: anywhere;
}

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

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

::selection {
    background: rgba(34,197,94,0.3);
    color: var(--text);
}

[hidden] {
    display: none !important;
}

.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.break-word {
    overflow-wrap: anywhere;
    word-break: break-word;
}

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

/* ===== LAYOUT (mobile first) ===== */
.app-layout {
    width: 100%;
    min-width: 0;
    min-height: 100vh;
    min-height: 100dvh;
}

.main-content {
    width: 100%;
    min-width: 0;
    margin-left: 0;
    padding: 16px;
    padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 16px);
}

.main-content > * {
    min-width: 0;
    max-width: 100%;
}

.sidebar {
    display: none;
}

.page-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 12px;
    width: 100%;
    min-width: 0;
    margin-bottom: 24px;
    padding-right: 56px;
}

.page-header h1 {
    min-width: 0;
    max-width: 100%;
    font-size: 20px;
    font-weight: 600;
    line-height: 1.3;
}

.page-header > * {
    min-width: 0;
    max-width: 100%;
}

.back-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: var(--text-sub);
    font-size: 13px;
    text-decoration: none;
}

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

.page-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    width: 100%;
}

.page-actions > .btn,
.page-actions > form,
.page-actions > form > .btn {
    width: 100%;
}

.page-actions > *,
.header-actions > * {
    min-width: 0;
    max-width: 100%;
}

.inline-form {
    display: flex;
    width: 100%;
}

.inline-form > .btn {
    width: 100%;
}

/* Shared responsive grids: one column through 700px. */
.detail-grid,
.two-column-grid,
.parcel-type-grid,
.form-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    min-width: 0;
}

.detail-grid > *,
.two-column-grid > *,
.parcel-type-grid > *,
.form-grid > * {
    min-width: 0;
    max-width: 100%;
}

.sticky-actions {
    position: sticky;
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    margin-top: 16px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
    box-shadow: 0 -4px 18px rgba(0,0,0,0.22);
}

.sticky-actions .btn {
    flex: 1 1 auto;
    width: 100%;
}

/* ===== BOTTOM NAVIGATION (mobile first) ===== */
.bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    height: calc(var(--bottom-nav-h) + var(--safe-bottom));
    padding: 0 max(4px, env(safe-area-inset-right, 0px)) var(--safe-bottom) max(4px, env(safe-area-inset-left, 0px));
    border-top: 1px solid var(--border);
    background: var(--card-bg);
}

.bottom-nav a {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 44px;
    padding: 6px 2px;
    color: var(--text-sub);
    font-size: 10px;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
}

.bottom-nav a.active {
    color: var(--accent);
}

.bottom-nav a span {
    max-width: 100%;
    overflow: hidden;
    overflow-wrap: anywhere;
    line-height: 1.1;
}

.bottom-nav svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

/* ===== CARDS ===== */
.card {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin-bottom: 16px;
    padding: 16px;
    overflow: visible;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
}

.card > * {
    min-width: 0;
    max-width: 100%;
}

.card-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    min-width: 0;
    max-width: 100%;
    font-size: 16px;
    font-weight: 600;
}

.card-header > * {
    min-width: 0;
    max-width: 100%;
}

/* ===== TABLES ===== */
.table-container {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
}

th, td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
    text-align: left;
    white-space: nowrap;
}

th {
    color: var(--text-sub);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover td {
    background: var(--hover-bg);
}

.table-link {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

.table-link:hover {
    text-decoration: underline;
}

/* Client/payment/analytics tables become cards on narrow screens. */
.mobile-card-table {
    min-width: 0;
}

.mobile-card-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.mobile-card-table tbody {
    display: block;
    width: 100%;
}

.mobile-card-table tr {
    display: block;
    width: 100%;
    margin: 0 0 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.mobile-card-table tr:last-child {
    margin-bottom: 0;
}

.mobile-card-table td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
    min-width: 0;
    padding: 6px 0;
    border: 0;
    font-size: 14px;
    text-align: right;
    white-space: normal;
    overflow-wrap: anywhere;
}

.mobile-card-table td > * {
    min-width: 0;
    overflow-wrap: anywhere;
}

.mobile-card-table td::before {
    content: attr(data-label);
    flex: 0 0 42%;
    min-width: 0;
    max-width: 42%;
    color: var(--text-sub);
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    overflow-wrap: anywhere;
}

.mobile-card-table td:not([data-label])::before,
.mobile-card-table td[data-label=""]::before {
    display: none;
}

.mobile-card-table td[data-label]:first-child {
    padding-top: 0;
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
}

.mobile-card-table td:last-child {
    padding-bottom: 0;
}

.mobile-card-table .cell-actions {
    align-items: center;
    padding-top: 10px;
    margin-top: 4px;
    border-top: 1px solid var(--border);
}

.mobile-card-table .cell-actions > * {
    max-width: 58%;
}

.mobile-card-table .cell-actions .btn {
    max-width: 100%;
}

.mobile-card-table td a:not(.btn) {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
}

.mobile-card-table .money {
    font-variant-numeric: tabular-nums;
}

/* ===== BADGES ===== */
.badge {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: 100%;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    white-space: normal;
    overflow-wrap: anywhere;
}

.badge-success { background: rgba(34,197,94,0.15); color: #86efac; }
.badge-warning { background: rgba(245,158,11,0.15); color: #fcd34d; }
.badge-info { background: rgba(59,130,246,0.15); color: #93c5fd; }
.badge-danger { background: rgba(239,68,68,0.15); color: #fca5a5; }
.badge-neutral { background: rgba(161,161,170,0.16); color: #d4d4d8; }

.light .badge-success { color: #166534; }
.light .badge-warning { color: #92400e; }
.light .badge-info { color: #1e40af; }
.light .badge-danger { color: #991b1b; }
.light .badge-neutral { color: #374151; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 44px;
    min-height: 44px;
    max-width: 100%;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    text-align: center;
    text-decoration: none;
    white-space: normal;
    overflow-wrap: anywhere;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.btn svg {
    flex-shrink: 0;
}

.btn-primary {
    border: 1px solid var(--accent-strong);
    background: var(--accent-strong);
    color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { opacity: 0.85; }

.btn-secondary {
    border: 1px solid var(--control-border);
    background: transparent;
    color: var(--text);
}

.btn-secondary:hover { background: var(--hover-bg); }
.btn-secondary:active { background: var(--active-bg); }

.btn-danger {
    border: 1px solid rgba(239,68,68,0.45);
    background: rgba(239,68,68,0.12);
    color: var(--danger);
}

.btn-danger:hover { background: rgba(239,68,68,0.22); }

.btn-sm {
    min-height: 44px;
    padding: 8px 12px;
    font-size: 13px;
}

.btn-icon {
    min-width: 44px;
    min-height: 44px;
    padding: 8px;
}

.btn:disabled,
button:disabled,
.form-control:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.theme-toggle {
    position: fixed;
    top: max(12px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--control-border);
    border-radius: 50%;
    background: var(--card-bg);
    color: var(--text);
    box-shadow: var(--shadow);
    cursor: pointer;
}

.theme-toggle:hover { background: var(--hover-bg); }

/* ===== FORMS ===== */
.form-group {
    min-width: 0;
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-sub);
    font-size: 14px;
    font-weight: 600;
}

.form-control {
    display: block;
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--control-border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.4;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.form-control::placeholder {
    color: var(--text-sub);
    opacity: 1;
}

.form-control:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 3px rgba(74,222,128,0.22);
}

.form-control:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.form-control[readonly] {
    background: var(--readonly-bg);
    color: var(--text);
    cursor: text;
}

textarea.form-control {
    min-height: 96px;
    resize: vertical;
}

select.form-control {
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.form-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    min-width: 0;
}

.form-hint {
    margin-top: 6px;
    color: var(--text-sub);
    font-size: 13px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.form-section-title {
    margin-bottom: 12px;
    color: var(--text-sub);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.finance-summary {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ===== SEARCH ===== */
.search-bar {
    width: 100%;
    min-width: 0;
    margin-bottom: 24px;
}

.search-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    width: 100%;
    min-width: 0;
}

.search-form .form-control {
    width: 100%;
    max-width: 100%;
}

/* ===== STATS ===== */
.stats-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    min-width: 0;
    margin-bottom: 24px;
}

.stat-card {
    min-width: 0;
    max-width: 100%;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
}

.stat-card .label {
    margin-bottom: 4px;
    color: var(--text-sub);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.stat-card .value {
    max-width: 100%;
    font-size: 24px;
    font-weight: 700;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

/* ===== MONEY ===== */
.money {
    font-variant-numeric: tabular-nums;
}

.money-positive { color: var(--success); }
.money-negative { color: var(--danger); }

/* ===== AUTH ===== */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 72px max(16px, env(safe-area-inset-right, 0px)) calc(24px + var(--safe-bottom)) max(16px, env(safe-area-inset-left, 0px));
}

.auth-card {
    width: 100%;
    min-width: 0;
    max-width: 400px;
    margin: auto;
    padding: 24px 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card-bg);
}

.auth-logo {
    display: block;
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
}

.auth-card h1 {
    margin-bottom: 8px;
    font-size: 24px;
    line-height: 1.3;
    text-align: center;
}

.auth-card .subtitle {
    margin-bottom: 24px;
    color: var(--text-sub);
    font-size: 14px;
    text-align: center;
}

.auth-card .btn {
    width: 100%;
    padding: 12px;
}

.password-wrap {
    position: relative;
    display: block;
}

.password-wrap .form-control {
    padding-right: 52px;
}

.password-toggle {
    position: absolute;
    top: 50%;
    right: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    transform: translateY(-50%);
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-sub);
    cursor: pointer;
}

.password-toggle:hover {
    background: var(--hover-bg);
    color: var(--accent);
}

.password-toggle:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 1px;
}

.password-toggle svg {
    display: block;
    width: 20px;
    height: 20px;
}

.password-toggle .icon-off { display: none; }
.password-toggle.is-visible .icon-on { display: none; }
.password-toggle.is-visible .icon-off { display: block; }

.remember-login {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    margin-top: 8px;
    color: var(--text-sub);
    font-size: 14px;
    cursor: pointer;
    user-select: none;
}

.remember-login input {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--accent-strong);
    cursor: pointer;
}

.auth-card .links {
    margin-top: 16px;
    color: var(--text-sub);
    font-size: 14px;
    text-align: center;
}

.auth-card .links a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: var(--accent);
    font-weight: 600;
}

.auth-note {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    color: var(--text-sub);
    font-size: 13px;
    text-align: center;
}

.auth-note a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
}

/* ===== MODAL / BOTTOM SHEET ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: none;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    background: rgba(0,0,0,0.68);
    overscroll-behavior: contain;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    padding: 20px max(16px, env(safe-area-inset-right, 0px)) calc(20px + var(--safe-bottom)) max(16px, env(safe-area-inset-left, 0px));
    overflow-y: auto;
    overscroll-behavior-y: contain;
    border: 1px solid var(--border);
    border-bottom: 0;
    border-radius: 20px 20px 0 0;
    background: var(--card-bg);
    box-shadow: 0 -12px 40px rgba(0,0,0,0.4);
    -webkit-overflow-scrolling: touch;
}

.modal h2 {
    margin-bottom: 20px;
    font-size: 18px;
    line-height: 1.35;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 24px;
}

.modal-actions .btn {
    width: 100%;
}

.product-meta,
.product-meta > span,
.product-meta span {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}

/* ===== PRODUCT CARD ===== */
.product-card {
    display: flex;
    gap: 12px;
    min-width: 0;
    max-width: 100%;
    margin-bottom: 12px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
}

.product-card .product-photo {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
    border-radius: 8px;
    object-fit: cover;
    background: var(--border);
}

.product-card .product-info {
    flex: 1;
    min-width: 0;
}

.product-card .product-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
    margin-bottom: 4px;
}

.product-card .product-header > * {
    min-width: 0;
    max-width: 100%;
}

.product-card .product-name {
    min-width: 0;
    max-width: 100%;
    font-size: 14px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.product-card .product-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    min-width: 0;
    max-width: 100%;
    margin-bottom: 8px;
    color: var(--text-sub);
    font-size: 13px;
}

.product-card .product-prices {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    min-width: 0;
    max-width: 100%;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 13px;
}

.product-card .product-prices > * {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.product-card .product-prices .label { color: var(--text-sub); }
.product-card .product-prices .value { font-weight: 600; }

/* ===== EMPTY STATE ===== */
.empty-state {
    padding: 40px 16px;
    color: var(--text-sub);
    text-align: center;
}

.empty-state h3 {
    margin-bottom: 8px;
    color: var(--text);
    font-size: 16px;
}

.empty-state p {
    max-width: 100%;
    margin-bottom: 20px;
    font-size: 14px;
    overflow-wrap: anywhere;
}

.empty-state .btn {
    max-width: 100%;
}

/* ===== SUMMARY ===== */
.summary-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.summary-row:last-child {
    border-bottom: 0;
}

.summary-row > span:first-child {
    flex: 0 1 45%;
    min-width: 0;
    color: var(--text-sub);
    overflow-wrap: anywhere;
}

.summary-row > span:last-child {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 500;
    text-align: right;
    overflow-wrap: anywhere;
}

/* ===== ALERTS ===== */
.alert {
    max-width: 100%;
    margin-bottom: 16px;
    padding: 12px 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 14px;
    overflow-wrap: anywhere;
}

.alert-success {
    border-color: rgba(34,197,94,0.4);
    background: rgba(34,197,94,0.1);
    color: #86efac;
}

.alert-error {
    border-color: rgba(239,68,68,0.45);
    background: rgba(239,68,68,0.1);
    color: #fca5a5;
}

.alert-warning {
    border-color: rgba(245,158,11,0.45);
    background: rgba(245,158,11,0.1);
    color: #fcd34d;
}

.alert-info {
    border-color: rgba(59,130,246,0.45);
    background: rgba(59,130,246,0.1);
    color: #93c5fd;
}

.light .alert-success { color: #166534; }
.light .alert-error { color: #991b1b; }
.light .alert-warning { color: #92400e; }
.light .alert-info { color: #1e40af; }

/* ===== SIDEBAR FOOTER / LOGOUT ===== */
.logout-form {
    width: 100%;
    margin: 0;
}

.logout-button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 44px;
    padding: 6px 0;
    border: 0;
    background: transparent;
    color: var(--text-sub);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.logout-button:hover {
    color: var(--text);
}

.logout-button svg {
    flex-shrink: 0;
}

.file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.file-input:focus-visible + .btn {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

/* ===== PARCEL WORKSPACE ===== */
.header-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    min-width: 0;
}

.header-actions > .btn,
.header-actions > form,
.header-actions > form > .btn {
    width: 100%;
}

.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    margin-top: 8px;
}

.badge-row > * {
    min-width: 0;
    max-width: 100%;
}

.muted { color: var(--text-sub); }
.text-info { color: var(--info); }
.text-accent { color: var(--accent); }

.product-photo-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-sub);
    font-size: 22px;
    font-weight: 700;
}

.product-title-wrap {
    flex: 1 1 auto;
    min-width: 0;
}

.product-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
}

.product-actions > * {
    min-width: 0;
    max-width: 100%;
}

.calculation-note {
    margin-top: 10px;
    color: var(--text-sub);
    font-size: 12px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.client-share-row {
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
}

.client-share-row:last-child { border-bottom: 0; }
.client-share-info { min-width: 0; }
.client-share-info > strong { overflow-wrap: anywhere; }

.share-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
    margin-top: 10px;
}

.share-actions > * {
    min-width: 0;
    max-width: 100%;
}

.client-settings {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px dashed var(--border);
}

.client-settings .form-group { margin-bottom: 0; }

.section-title {
    margin: 24px 0 12px;
    color: var(--text-sub);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.summary-total {
    margin-top: 6px;
    padding-top: 14px;
    border-top: 2px solid var(--border);
    font-weight: 700;
}

.narrow-card {
    max-width: 820px;
    margin-right: auto;
    margin-left: auto;
}

.full-width { width: 100%; }

.checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-height: 44px;
    margin-bottom: 16px;
}

.checkbox-row label {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    min-height: 44px;
    overflow-wrap: anywhere;
    cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    accent-color: var(--accent-strong);
}

.type-selector {
    min-width: 0;
    margin: 0 0 20px;
    padding: 0;
    border: 0;
}

.type-selector legend {
    margin-bottom: 8px;
    color: var(--text-sub);
    font-size: 14px;
    font-weight: 600;
}

.type-selector label {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 2px 10px;
    margin-bottom: 8px;
    padding: 12px;
    border: 1px solid var(--control-border);
    border-radius: 10px;
    background: var(--bg);
    cursor: pointer;
}

.type-selector label.selected {
    border-color: var(--accent);
    background: rgba(34,197,94,0.08);
}

.type-selector input {
    grid-row: 1 / span 2;
    width: 20px;
    height: 20px;
    margin-top: 2px;
    accent-color: var(--accent-strong);
}

.type-selector strong,
.type-selector label > span { min-width: 0; }

.type-selector label > span {
    color: var(--text-sub);
    font-size: 13px;
}

.desktop-table { display: none; }

.mobile-parcel-list {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
}

.mobile-parcel-card {
    display: block;
    margin-bottom: 0;
    color: var(--text);
    text-decoration: none;
}

.mobile-parcel-card:hover {
    border-color: var(--control-border);
    background: var(--surface);
}

.mobile-parcel-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    margin-bottom: 8px;
}

.mobile-parcel-top > * {
    min-width: 0;
    max-width: 100%;
}

.mobile-parcel-top > strong {
    min-width: 0;
    overflow-wrap: anywhere;
}

.mobile-parcel-money {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.mobile-parcel-money > div { min-width: 0; }
.mobile-parcel-money > div:only-child { grid-column: 1 / -1; }
.mobile-parcel-money .label {
    display: block;
    margin-bottom: 2px;
    color: var(--text-sub);
    font-size: 12px;
}

.mobile-parcel-money strong {
    display: block;
    overflow-wrap: anywhere;
}

.list-count {
    margin-top: 12px;
    color: var(--text-sub);
    font-size: 13px;
    text-align: right;
}

/* ===== PUBLIC CLIENT SHARE ===== */
body.share-page {
    padding: 0 max(16px, env(safe-area-inset-right, 0px)) calc(24px + var(--safe-bottom)) max(16px, env(safe-area-inset-left, 0px));
}

.share-container {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding-top: max(24px, env(safe-area-inset-top, 0px));
}

.share-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    margin-bottom: 20px;
}

.share-header h1 {
    min-width: 0;
    font-size: 22px;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.share-header > .badge {
    grid-column: 1 / -1;
    justify-self: start;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--accent-strong);
    color: #fff;
    font-weight: 800;
}

.share-client-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
}

.share-client-card > * {
    min-width: 0;
    overflow-wrap: anywhere;
}

.share-client-card .label {
    display: block;
    margin-bottom: 2px;
    color: var(--text-sub);
    font-size: 12px;
}

.share-total {
    color: var(--accent);
    font-size: 22px;
    overflow-wrap: anywhere;
}

.share-item {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.share-item:last-child { border-bottom: 0; }
.share-item-main { min-width: 0; }
.share-item-main > strong { overflow-wrap: anywhere; }

.share-item-price {
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.share-disclaimer {
    color: var(--text-sub);
    font-size: 13px;
    line-height: 1.5;
}

/* ===== SCANNER ===== */
.scanner-card {
    max-width: 600px;
    margin-right: auto;
    margin-left: auto;
}

.quick-add-card {
    max-width: 720px;
}

.quick-add-card h2 {
    margin-bottom: 8px;
    font-size: 16px;
}

.quick-add-tracking {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--accent);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 16px;
    line-height: 1.5;
    white-space: normal;
    overflow-wrap: anywhere;
}

.quick-add-selection {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    margin: 20px 0;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.quick-add-selection > * {
    min-width: 0;
    max-width: 100%;
}

.quick-add-selection > div {
    flex: 1 1 200px;
}

.quick-add-selection .label {
    display: block;
    margin-bottom: 2px;
    color: var(--text-sub);
    font-size: 12px;
}

.quick-add-parcel-form,
.quick-add-product-form {
    width: 100%;
    min-width: 0;
}

.scanner-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    width: 100%;
}

.scanner-actions .btn,
.scanner-actions label.btn {
    width: 100%;
    cursor: pointer;
}

#reader {
    display: none;
    width: 100%;
    max-width: 400px;
    margin: 12px auto 0;
    overflow: hidden;
    border-radius: 12px;
}

#reader video {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 12px;
}

#reader img[alt="Info icon"] {
    display: none;
}

.scan-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.scan-status {
    min-height: 24px;
    margin-top: 12px;
    color: var(--text-sub);
    font-size: 14px;
    text-align: center;
    overflow-wrap: anywhere;
}

.scan-status.is-error { color: var(--danger); }
.scan-status.is-success { color: var(--success); }

.scan-result {
    display: none;
    width: 100%;
    min-width: 0;
    max-width: 600px;
    margin: 16px auto;
    padding: 16px;
    border: 1px solid rgba(34,197,94,0.4);
    border-radius: 8px;
    background: rgba(34,197,94,0.1);
    text-align: center;
}

.scan-result.show { display: block; }

.scan-result code {
    display: block;
    min-width: 0;
    max-width: 100%;
    color: var(--accent);
    font-size: 18px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.scan-result-label {
    margin-bottom: 4px;
    color: var(--text-sub);
    font-size: 12px;
}

.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 600px;
    margin: 20px auto;
    color: var(--text-sub);
    font-size: 13px;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ===== PROGRESSIVE ENHANCEMENTS ===== */
@media (min-width: 360px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 480px) {
    .search-form {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .scanner-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .scan-controls {
        flex-direction: row;
        justify-content: center;
    }
}

/* Required one-column breakpoint for shared layout classes. */
@media (min-width: 701px) {
    .main-content {
        padding: 24px;
        padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 24px);
    }

    .page-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    .page-header h1 { font-size: 24px; }

    .page-actions {
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
        width: auto;
    }

    .page-actions > .btn,
    .page-actions > form,
    .page-actions > form > .btn {
        width: auto;
    }

    .header-actions {
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
        width: auto;
    }

    .header-actions > .btn,
    .header-actions > form,
    .header-actions > form > .btn {
        width: auto;
    }

    .client-settings {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: end;
    }

    .client-settings > .btn {
        grid-column: 1 / -1;
        justify-self: start;
    }

    .type-selector {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    .type-selector legend { grid-column: 1 / -1; }
    .type-selector label { margin-bottom: 0; }

    .desktop-table { display: block; }
    .mobile-parcel-list { display: none; }

    .share-header {
        grid-template-columns: auto minmax(0, 1fr) auto;
    }

    .share-header > .badge { grid-column: auto; }
    .share-client-card { grid-template-columns: repeat(3, minmax(0, 1fr)); }

    .share-item {
        flex-direction: row;
        align-items: flex-start;
        justify-content: space-between;
        gap: 20px;
    }

    .share-item-price { flex-shrink: 0; text-align: right; }

    .detail-grid,
    .two-column-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .parcel-type-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .form-row,
    .form-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }

    .sticky-actions {
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
    }

    .sticky-actions .btn {
        flex: 0 1 auto;
        width: auto;
    }

    .card { padding: 24px; }
    .card-header { flex-direction: row; align-items: center; }

    table,
    .mobile-card-table {
        min-width: 600px;
    }

    .mobile-card-table thead {
        position: static;
        width: auto;
        height: auto;
        margin: 0;
        overflow: visible;
        clip: auto;
        clip-path: none;
    }

    .mobile-card-table tbody { display: table-row-group; }

    .mobile-card-table tr {
        display: table-row;
        width: auto;
        margin: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: transparent;
    }

    .mobile-card-table td {
        display: table-cell;
        width: auto;
        padding: 12px 16px;
        border-bottom: 1px solid var(--border);
        font-size: 14px;
        font-weight: 400;
        text-align: left;
        white-space: nowrap;
    }

    .mobile-card-table td::before { display: none; }

    .mobile-card-table td:first-child { padding-top: 12px; font-size: 14px; }
    .mobile-card-table td:last-child { padding-bottom: 12px; }

    .mobile-card-table .cell-actions {
        margin: 0;
        padding: 12px 16px;
        border: 0;
        border-bottom: 1px solid var(--border);
    }

    .mobile-card-table .cell-actions > * { max-width: none; }

    .modal-overlay {
        align-items: center;
        padding: 16px;
    }

    .modal {
        max-width: 500px;
        max-height: 90vh;
        max-height: 90dvh;
        padding: 32px 24px;
        border: 1px solid var(--border);
        border-radius: 16px;
    }

    .modal-actions {
        flex-direction: row;
        justify-content: flex-end;
    }

    .modal-actions .btn { width: auto; }
    .auth-card { padding: 32px 24px; }
}

@media (min-width: 769px) {
    .app-layout { display: flex; }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 120;
        display: flex;
        flex-direction: column;
        width: var(--sidebar-w);
        padding: 24px 0;
        overflow-y: auto;
        border-right: 1px solid var(--border);
        background: var(--card-bg);
        -webkit-overflow-scrolling: touch;
    }

    .sidebar-logo {
        display: flex;
        flex-shrink: 0;
        align-items: center;
        gap: 12px;
        margin-bottom: 32px;
        padding: 0 20px;
    }

    .sidebar-logo img { height: 32px; }
    .sidebar-logo svg { height: 32px; }

    .sidebar-logo span {
        color: var(--text);
        font-size: 16px;
        font-weight: 600;
    }

    .sidebar-nav { flex: 1; }

    .sidebar-nav a {
        display: flex;
        align-items: center;
        gap: 12px;
        min-height: 44px;
        padding: 10px 20px;
        border-left: 3px solid transparent;
        color: var(--text-sub);
        font-size: 14px;
        text-decoration: none;
    }

    .sidebar-nav a:hover,
    .sidebar-nav a:active {
        background: var(--hover-bg);
        color: var(--text);
    }

    .sidebar-nav a.active {
        border-left-color: var(--accent);
        background: rgba(34,197,94,0.08);
        color: var(--accent);
    }

    .sidebar-nav a svg {
        width: 18px;
        height: 18px;
        flex-shrink: 0;
    }

    .sidebar-footer {
        flex-shrink: 0;
        padding: 16px 20px;
        border-top: 1px solid var(--border);
    }

    .main-content {
        flex: 1;
        width: calc(100% - var(--sidebar-w));
        max-width: 1400px;
        margin-left: var(--sidebar-w);
        padding: 32px;
    }

    .table-container {
        margin: 0 -24px;
        padding: 0 24px;
    }

    .bottom-nav { display: none; }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 16px;
    }

    .stat-card { padding: 20px; }
    .stat-card .value { font-size: 28px; }

    .sticky-actions { bottom: 16px; }
    .theme-toggle { top: 16px; right: 16px; }
}

@media (max-width: 560px) {
    .product-card .product-header {
        flex-direction: column;
    }

    .product-actions {
        justify-content: flex-start;
        width: 100%;
    }

    .product-actions > .btn,
    .product-actions > form,
    .product-actions > form > .btn {
        flex: 1 1 auto;
    }
}

@media (max-width: 380px) {
    .main-content { padding: 12px; padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 12px); }
    .stats-grid { grid-template-columns: minmax(0, 1fr); }
    .auth-card { padding: 20px 14px; }
    .product-card { padding: 12px; }
    .product-card .product-photo { width: 64px; height: 64px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        transition: none !important;
        animation: none !important;
    }
}
