/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f5f7fa;
    --surface: #ffffff;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #f59e0b;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.hidden { display: none !important; }

/* ── Navigation ──────────────────────────────────────────── */
nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
}

.nav-links { display: flex; gap: 0.5rem; flex: 1; }

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: var(--primary); color: #fff; }

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.15s;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.8rem; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }

/* ── Pages ───────────────────────────────────────────────── */
.page { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.page-header h2 { font-size: 1.5rem; }

/* ── Login ───────────────────────────────────────────────── */
.login-card {
    max-width: 360px;
    margin: 15vh auto;
    padding: 2rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
}
.login-card h1 { margin-bottom: 1.5rem; color: var(--primary); }
.login-card input {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
}
.login-card .btn { width: 100%; padding: 0.75rem; font-size: 1rem; }

.error { color: var(--danger); margin-top: 0.5rem; font-size: 0.875rem; }
.warning { color: var(--warning); background: #fef3c7; padding: 0.5rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.875rem; }

/* ── Search ──────────────────────────────────────────────── */
.search-input {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    width: 300px;
}

/* ── Home layout (sidebar + main) ────────────────────────── */
.home-layout {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}

.home-sidebar {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.profile-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}

.profile-card h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.profile-row {
    display: flex;
    justify-content: space-between;
    padding: 0.35rem 0;
    font-size: 0.9rem;
}

.profile-label {
    color: var(--text-secondary);
}

.profile-value {
    font-weight: 600;
}

.wip-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-style: italic;
    padding: 0.5rem 0;
}

.home-main {
    flex: 1;
    min-width: 0;
}

.search-hero {
    display: flex;
    justify-content: center;
    padding: 2rem 0 1.5rem;
}

.search-hero-centered {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 4rem 1rem 2rem;
}

.search-input-lg {
    width: 100%;
    max-width: 600px;
    padding: 0.85rem 1.5rem;
    font-size: 1.2rem;
    border: 2px solid var(--border);
    border-radius: 2rem;
    transition: border-color 0.2s;
}

.search-input-xl {
    width: 100%;
    max-width: 800px;
    padding: 1.1rem 2rem;
    font-size: 1.35rem;
    border: 2px solid var(--border);
    border-radius: 2rem;
    transition: border-color 0.2s;
}

.search-input-xl:focus,
.search-input-lg:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* ── Profile page ──────────────────────────────────────── */
.profile-page-content {
    max-width: 600px;
    margin: 0 auto;
    padding: 1rem;
}

.profile-card-lg {
    padding: 2rem;
}

.profile-card-lg .profile-row {
    padding: 0.75rem 0;
    font-size: 1.05rem;
}

/* ── Cards (inventory items) ─────────────────────────────── */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.item-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}
.item-card h3 { font-size: 1rem; margin-bottom: 0.5rem; word-break: break-word; }
.item-meta { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.75rem; }
.item-meta span { display: inline-block; margin-right: 1rem; }
.item-stock { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.75rem; }
.item-stock.low { color: var(--danger); }
.item-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.item-actions .btn {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    text-align: center;
    border-radius: var(--radius);
}

.source-section { margin-bottom: 1.5rem; }
.source-section h3 { color: var(--text-secondary); text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.05em; margin-bottom: 0.75rem; padding-bottom: 0.25rem; border-bottom: 1px solid var(--border); }

/* ── Tables ──────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.data-table th, .data-table td {
    padding: 0.6rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}
.data-table th { background: var(--bg); font-weight: 600; color: var(--text-secondary); }
.data-table tr:hover td { background: #f8fafc; }
.data-table tr { cursor: pointer; }
.data-table tr.order-done td { background: #dcfce7; }
.data-table tr.order-done:hover td { background: #bbf7d0; }
.data-table tr.order-pending td { background: #fee2e2; }
.data-table tr.order-pending:hover td { background: #fecaca; }
.btn-approve { background: #16a34a; color: #fff; border: none; border-radius: 4px; padding: 0.25rem 0.75rem; font-size: 0.8rem; cursor: pointer; }
.btn-approve:hover { background: #15803d; }

/* ── Inline cell editing ────────────────────────────────── */
.data-table td.editable { cursor: cell; }
.data-table td.editable:hover { background: #eff6ff; outline: 1px dashed var(--primary); outline-offset: -1px; }
.data-table td.cell-editing {
    padding: 0;
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}
.data-table td.cell-editing input {
    width: 100%;
    height: 100%;
    padding: 0.4rem 0.5rem;
    border: none;
    font-size: inherit;
    font-family: inherit;
    background: #eff6ff;
    outline: none;
}
.data-table td.cell-saved {
    animation: cellSaved 1.2s ease-out;
}
.data-table td.cell-error {
    animation: cellError 1.2s ease-out;
}
@keyframes cellSaved {
    0% { background: #bbf7d0; }
    100% { background: transparent; }
}
@keyframes cellError {
    0% { background: #fecaca; }
    100% { background: transparent; }
}

/* ── Tables browser ──────────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
    max-width: 100%;
    margin-bottom: 1rem;
}
.table-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    min-width: 200px;
}
.per-page-select {
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    margin-left: 0.5rem;
}
.pagination {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    justify-content: center;
    padding: 0.75rem;
}
#table-data th {
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}
#table-data th:hover {
    background: #e2e8f0;
}
#table-data td {
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Modal ───────────────────────────────────────────────── */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 200;
}
.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    min-width: 320px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 24px rgba(0,0,0,0.15);
}
.modal-lg { min-width: 600px; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* ── Forms ───────────────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}
.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}
.form-group input, .form-group textarea, .form-group select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
}
.full-width { grid-column: 1 / -1; }

.inline-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.inline-form input { flex: 1; padding: 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); }

/* ── Tabs ────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; }
.tab {
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Notes ───────────────────────────────────────────────── */
.note-item {
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
}
.note-item .note-meta { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.25rem; }

/* ── Toast ───────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.toast {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    color: #fff;
    font-size: 0.875rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    animation: slideIn 0.3s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Status badges ───────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-ok { background: #dcfce7; color: var(--success); }
.badge-warn { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: var(--danger); }
.badge-muted { background: #f3f4f6; color: #6b7280; }

/* ── Admin ───────────────────────────────────────────────── */
.header-actions { display: flex; gap: 0.5rem; }

.info-banner {
    padding: 0.75rem 1rem;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.role-select {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    background: var(--surface);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-danger:hover { background: #b91c1c; }

/* ── Language select ────────────────────────────────────── */
.lang-select {
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    background: var(--surface);
    cursor: pointer;
}

/* ── Search results list (clickable rows) ────────────────── */
.search-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.search-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.search-row:hover {
    background: #eff6ff;
    border-color: var(--primary);
}

.search-row-icon { font-size: 1.1rem; flex-shrink: 0; }
.search-row-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-row-meta { color: var(--text-secondary); font-size: 0.8rem; flex-shrink: 0; }
.search-row-stock { font-weight: 700; font-size: 0.9rem; flex-shrink: 0; min-width: 2rem; text-align: right; }
.search-row-stock.low { color: var(--danger); }

/* ── Item detail card ────────────────────────────────────── */
.item-detail-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    max-width: 600px;
}

.item-detail-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.item-detail-header h3 { font-size: 1.25rem; word-break: break-word; }
.item-detail-icon { font-size: 1.5rem; }

.item-detail-fields { margin-bottom: 1.25rem; }
.field-row {
    padding: 0.2rem 0;
    font-size: 0.95rem;
    line-height: 1.6;
}
.field-row b.low { color: var(--danger); }

.location-hidden { color: var(--text-secondary); font-style: italic; }
.location-revealed { color: var(--success); font-weight: 600; }

.card-footer-hint {
    padding: 0.5rem 0;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
}

.item-back { margin-top: 1rem; }

.btn-action { white-space: nowrap; }

/* ── Pagination ─────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem 0;
}
.pagination-info { font-size: 0.875rem; color: var(--text-secondary); }

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.pagination-controls select {
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    background: var(--surface);
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    nav { flex-wrap: wrap; }
    .nav-links { order: 3; width: 100%; }
    .search-input { width: 100%; }
    .form-grid { grid-template-columns: 1fr; }
    .modal-lg { min-width: 95vw; }
    .cards-grid { grid-template-columns: 1fr; }
    .home-layout { flex-direction: column; }
    .home-sidebar { width: 100%; }
    .search-input-lg { max-width: 100%; }
}
