* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f5f6f8;
    color: #1f2933;
}

header {
    background: #1f2933;
    color: #fff;
    padding: 1rem 2rem;
}

header h1 {
    margin: 0 0 0.5rem;
    font-size: 1.4rem;
}

nav a {
    color: #cbd2d9;
    text-decoration: none;
    margin-right: 1.5rem;
    font-weight: 600;
}

nav a:hover {
    color: #fff;
}

main {
    max-width: 1000px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

h2 {
    margin-top: 0;
}

.subtitle {
    color: #616e7c;
    margin-top: -0.5rem;
}

/* Flash messages */
.flashes {
    margin-bottom: 1.5rem;
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.flash-success {
    background: #def7ec;
    color: #03543f;
    border: 1px solid #84e1bc;
}

.flash-error {
    background: #fde8e8;
    color: #9b1c1c;
    border: 1px solid #f8b4b4;
}

/* Tables */
.stock-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    overflow: hidden;
}

.stock-table th,
.stock-table td {
    text-align: left;
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid #e4e7eb;
    font-size: 0.92rem;
}

.stock-table th {
    background: #e4e7eb;
    font-weight: 600;
}

.stock-table tr.low-stock {
    background: #fff5f5;
}

.flag {
    display: inline-block;
    background: #e02424;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    margin-left: 0.4rem;
}

/* Forms */
input[type="text"],
input[type="number"],
input[type="file"] {
    padding: 0.4rem 0.5rem;
    border: 1px solid #cbd2d9;
    border-radius: 5px;
    font-size: 0.9rem;
    width: 100%;
}

.inline-form {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.inline-form input[type="number"] {
    width: 80px;
}

button,
.button-secondary {
    background: #2563eb;
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

button:hover,
.button-secondary:hover {
    background: #1d4ed8;
}

.button-secondary {
    background: #616e7c;
}

.button-secondary:hover {
    background: #52606d;
}

.upload-form {
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    display: flex;
    gap: 1rem;
    align-items: center;
    max-width: 600px;
}

.upload-form input[type="file"] {
    flex: 1;
}

.actions {
    margin-top: 1rem;
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.raw-response {
    background: #1f2933;
    color: #e4e7eb;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.85rem;
    white-space: pre-wrap;
}

footer {
    text-align: center;
    color: #9aa5b1;
    font-size: 0.8rem;
    padding: 2rem 0;
}

/* =========================================================================
   Top navigation (logged-in)
   ========================================================================= */
.topnav {
    background: #1A1A2E;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    padding: 0 2rem;
}

.topnav-brand {
    color: #fff;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.topnav-links {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.topnav-links a {
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.95rem;
    padding: 0.4rem 0;
    border-bottom: 2px solid transparent;
}

.topnav-links a:hover { color: #cdd3ff; }

.topnav-links a.active {
    border-bottom-color: #4f8cff;
}

/* Logout: small and subtle, far right after Orders */
.topnav-logout {
    font-weight: 500 !important;
    font-size: 0.8rem !important;
    color: #8b8ea3 !important;
    margin-left: 0.25rem;
}
.topnav-logout:hover { color: #fff !important; }

/* Main content when logged in (top nav, full width) */
.app-shell .main-area {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 2.5rem;
}

/* Auth pages: centred card */
.auth-shell .main-area {
    max-width: 440px;
    margin: 4rem auto;
    padding: 0 1.5rem;
}

@media (max-width: 640px) {
    .topnav {
        flex-direction: column;
        height: auto;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
    }
    .topnav-links { gap: 1.25rem; }
    .app-shell .main-area { padding: 1.5rem 1.25rem; }
}

/* =========================================================================
   Auth cards (Upgrade 2)
   ========================================================================= */
.auth-card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    padding: 2rem;
}

.auth-brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1A1A2E;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    margin-top: 1rem;
}

.auth-form label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #3e4c59;
}

.auth-form input {
    font-weight: 400;
}

.auth-form button {
    margin-top: 0.5rem;
    padding: 0.65rem;
    font-size: 1rem;
}

.optional { color: #9aa5b1; font-weight: 400; }

.auth-switch {
    margin-top: 1.25rem;
    text-align: center;
    font-size: 0.9rem;
    color: #616e7c;
}

/* =========================================================================
   Upload loading — bouncing dots (Fix 1)
   ========================================================================= */
.bouncing-dots {
    display: none;
    justify-content: center;
    align-items: center;
    gap: 0.7rem;
    padding: 4rem 0;
    background: #fff;
}
.bouncing-dots.show { display: flex; }

.bouncing-dots span {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #1A1A2E;
    animation: dot-bounce 1.2s infinite ease-in-out both;
}
.bouncing-dots span:nth-child(1) { animation-delay: -0.32s; }
.bouncing-dots span:nth-child(2) { animation-delay: -0.16s; }
.bouncing-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes dot-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-18px); opacity: 1; }
}

/* =========================================================================
   Summary cards (Upgrade 4)
   ========================================================================= */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.card {
    background: #1A1A2E;
    color: #fff;
    border-radius: 10px;
    padding: 1.25rem 1.4rem;
}

.card-number {
    font-size: 1.9rem;
    font-weight: 700;
    line-height: 1.1;
}

.card-label {
    font-size: 0.82rem;
    color: #b8bcd0;
    margin-top: 0.35rem;
}

.card-alert { background: #C0392B; }
.card-alert .card-label { color: #f5d8d4; }

/* =========================================================================
   Search + filter controls (Upgrade 5)
   ========================================================================= */
.table-controls {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.table-controls #search-input {
    flex: 1;
    min-width: 220px;
}

.table-controls select {
    padding: 0.4rem 0.5rem;
    border: 1px solid #cbd2d9;
    border-radius: 5px;
    font-size: 0.9rem;
    background: #fff;
}

.no-results-cell {
    text-align: center;
    color: #616e7c;
    padding: 1.5rem;
    font-style: italic;
}

/* =========================================================================
   Inline stock adjustment (Upgrade 3)
   ========================================================================= */
.btn-small {
    padding: 0.35rem 0.7rem;
    font-size: 0.85rem;
}

.btn-danger { background: #C0392B; }
.btn-danger:hover { background: #a93226; }

.row-actions { white-space: nowrap; }

.adjust-row > td {
    background: #eef1f7;
}

.adjust-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
    align-items: flex-end;
}

.adjust-current {
    align-self: center;
    font-size: 0.9rem;
    color: #3e4c59;
}

.adjust-form label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: #3e4c59;
}

.adjust-form input,
.adjust-form select {
    font-weight: 400;
    width: auto;
}

.adjust-form .adjust-notes { flex: 1; min-width: 160px; }
.adjust-form .adjust-notes input { width: 100%; }

.adjust-actions { display: flex; gap: 0.5rem; }

/* =========================================================================
   Responsive layout (Upgrade 1)
   ========================================================================= */
/* Tables scroll horizontally on narrow screens instead of breaking */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table-scroll .stock-table {
    min-width: 720px;
}

@media (max-width: 768px) {
    .summary-cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
    .upload-form {
        flex-direction: column;
        align-items: stretch;
        max-width: none;
    }
    .table-controls { flex-direction: column; }
    .table-controls #search-input,
    .table-controls select { min-width: 0; width: 100%; }

    /* Comfortable touch targets on phones */
    button,
    .button-secondary,
    .topnav-links a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .btn-small { min-height: 38px; }
}

@media (max-width: 480px) {
    .summary-cards { grid-template-columns: 1fr; }
}
