:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f4f6fb;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --muted: #64748b;
    --danger: #dc2626;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    padding: 24px;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
}

h1 {
    text-align: center;
    margin-bottom: 6px;
    color: var(--primary-dark);
}

.subtitle {
    text-align: center;
    color: var(--muted);
    margin-bottom: 28px;
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    padding: 24px;
    margin-bottom: 28px;
}

.card h2 {
    margin-top: 0;
    font-size: 18px;
    color: var(--primary-dark);
}

form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

label {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
}

input[type="text"],
input[type="number"],
select {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}

input:focus,
select:focus {
    border-color: var(--primary);
}

.file-field {
    display: flex;
    align-items: center;
    gap: 12px;
}

.file-btn {
    display: inline-block;
    padding: 10px 14px;
    background: #eef2ff;
    border: 1px dashed var(--primary);
    border-radius: 8px;
    color: var(--primary-dark);
    cursor: pointer;
    font-size: 13px;
    text-align: center;
}

input[type="file"] {
    display: none;
}

#imagePreview {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--border);
    display: none;
}

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

button {
    cursor: pointer;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    padding: 11px 20px;
    transition: background 0.15s, transform 0.05s;
}

button:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: #f1f5f9;
    color: var(--text);
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.toolbar input[type="text"] {
    min-width: 220px;
}

.count-badge {
    background: #eef2ff;
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

tbody tr:hover {
    background: #f8fafc;
}

.item-thumb {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--border);
    background: #f1f5f9;
}

.no-image {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 10px;
    border: 1px solid var(--border);
}

.dept-tag {
    background: #f0fdf4;
    color: #166534;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.qty-tag {
    font-weight: 700;
}

.alert-low {
    color: var(--danger);
    font-weight: 700;
    font-size: 12px;
}

.alert-ok {
    color: #166534;
    font-weight: 700;
    font-size: 12px;
}

.notify-card .notify-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.low-stock-banner {
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--danger);
    font-size: 13px;
    font-weight: 600;
}

.updated-cell {
    font-size: 12px;
    color: var(--muted);
}

.row-actions button {
    padding: 6px 10px;
    font-size: 12px;
    margin-right: 6px;
}

.btn-delete {
    background: #fef2f2;
    color: var(--danger);
}

.btn-delete:hover {
    background: #fee2e2;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--muted);
}

.save-status {
    font-size: 12px;
    color: var(--muted);
    text-align: right;
    margin-top: 6px;
    min-height: 16px;
}

.view-btn {
    background: #eef2ff;
    color: var(--primary-dark);
}

.view-btn:hover {
    background: #e0e7ff;
}

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}

.modal-overlay.open {
    display: flex;
}

.modal-card {
    background: #fff;
    border-radius: 14px;
    max-width: 420px;
    width: 100%;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.modal-header h3 {
    margin: 0;
    color: var(--primary-dark);
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--muted);
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text);
}

.modal-image {
    width: 100%;
    max-height: 220px;
    object-fit: contain;
    border-radius: 10px;
    background: #f1f5f9;
    border: 1px solid var(--border);
    margin-bottom: 18px;
}

.modal-image-placeholder {
    width: 100%;
    height: 160px;
    border-radius: 10px;
    background: #f1f5f9;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 18px;
}

.modal-detail-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.modal-detail-row:last-of-type {
    border-bottom: none;
}

.modal-detail-label {
    color: var(--muted);
    font-weight: 600;
}

.modal-detail-value {
    text-align: right;
    font-weight: 600;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.item-name-link {
    color: var(--primary-dark);
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
}

.item-name-link:hover {
    text-decoration: underline;
}

.role-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    border-radius: 999px;
    background: #eef2ff;
    color: var(--primary-dark);
    vertical-align: middle;
}

.role-badge.role-guest {
    background: #fef9c3;
    color: #854d0e;
}

.calc-hint {
    font-size: 12px;
    color: var(--muted);
    min-height: 14px;
}

.measure-cell {
    font-size: 13px;
    color: var(--text);
}

.measure-cell .measure-sub {
    display: block;
    font-size: 11px;
    color: var(--muted);
}

.pwa-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 300;
    background: #fef9c3;
    color: #854d0e;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 12px;
}

.install-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 250;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 12px 18px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 8px 20px rgba(29, 78, 216, 0.35);
}

.install-btn:hover {
    background: var(--primary-dark);
}

.auth-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #1d4ed8, #1e293b);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 200;
}

.auth-card {
    background: #fff;
    border-radius: 14px;
    max-width: 380px;
    width: 100%;
    padding: 30px 28px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.auth-title {
    text-align: center;
    margin: 0 0 4px;
    color: var(--primary-dark);
    font-size: 22px;
}

.auth-subtitle {
    text-align: center;
    color: var(--muted);
    margin: 0 0 20px;
    font-size: 13px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.auth-hint {
    font-size: 12px;
    color: var(--muted);
    margin: 0 0 4px;
    line-height: 1.5;
}

.auth-error {
    color: var(--danger);
    font-size: 12px;
    font-weight: 600;
    min-height: 14px;
}

.auth-submit {
    width: 100%;
}

.auth-switch {
    text-align: center;
    font-size: 12px;
    color: var(--muted);
    margin: 0;
}

.auth-switch a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

.session-info {
    font-size: 13px;
    color: var(--muted);
}

.top-bar-actions {
    display: flex;
    gap: 10px;
}

.top-bar-actions button {
    padding: 8px 14px;
    font-size: 12px;
}

.tx-history {
    margin-top: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.tx-history h4 {
    margin: 6px 0 10px;
    font-size: 13px;
    color: var(--primary-dark);
}

.tx-list {
    max-height: 160px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tx-empty {
    font-size: 12px;
    color: var(--muted);
}

.tx-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    background: #f8fafc;
    border-radius: 8px;
    padding: 8px 10px;
}

.tx-row .tx-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tx-row .tx-meta {
    color: var(--muted);
    font-size: 11px;
}

.tx-in {
    color: #166534;
    font-weight: 700;
}

.tx-out {
    color: var(--danger);
    font-weight: 700;
}

.stock-move-actions {
    display: flex;
    gap: 6px;
}

.stock-move-actions button {
    padding: 6px 10px;
    font-size: 12px;
}

.btn-stock-in {
    background: #dcfce7;
    color: #166534;
}

.btn-stock-in:hover {
    background: #bbf7d0;
}

.btn-stock-out {
    background: #fef2f2;
    color: var(--danger);
}

.btn-stock-out:hover {
    background: #fee2e2;
}

.users-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 18px;
    max-height: 160px;
    overflow-y: auto;
}

.user-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
}

.user-row button {
    padding: 5px 10px;
    font-size: 11px;
}

@media (max-width: 640px) {
    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }
    thead {
        display: none;
    }
    tr {
        margin-bottom: 14px;
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 10px;
    }
    td {
        border: none;
        padding: 6px 4px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--muted);
        font-size: 11px;
        text-transform: uppercase;
    }
}


/* ---- Link back to the main purlinautomation.in site ---- */

.back-to-site {
    display: inline-block;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted, #64748b);
    text-decoration: none;
    margin-right: auto;
}

.back-to-site:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

.auth-back {
    display: block;
    margin: 6px 0 0;
    text-align: center;
}