/* Author: Kenny Coltharp
 * Version: 1.0
 * Copyright: 2026
 *
 * This file is part of ShoppingList.
 *
 * ShoppingList is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, either version
 * 3 of the License, or (at your option) any later version.
 *
 * ShoppingList is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ShoppingList. If not, see <https://www.gnu.org/licenses/>.
 */

/* =========================================
   Design tokens — see DESIGN.md
   ========================================= */
:root {
    --amber-50:  #fffbeb;
    --amber-100: #fef3c7;
    --amber-200: #fde68a;
    --amber-300: #fcd34d;
    --amber-400: #fbbf24;
    --amber-500: #f59e0b;
    --amber-600: #d97706;
    --amber-700: #b45309;
    --amber-800: #92400e;
    --amber-900: #78350f;
    --orange-500: #f97316;
    --red-500:   #ef4444;
    --green-500: #22c55e;
    --green-600: #16a34a;
    --blue-500:  #3b82f6;
    --gray-100:  #f3f4f6;
    --gray-400:  #9ca3af;
    --gray-700:  #374151;

    --font-display: "Fraunces", Georgia, serif;
    --font-body: "Instrument Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-data: "Geist", "Instrument Sans", sans-serif;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-full: 999px;
    --shadow:    0 1px 3px rgba(120,53,15,.08), 0 1px 2px rgba(120,53,15,.05);
    --shadow-md: 0 6px 16px rgba(120,53,15,.12), 0 2px 6px rgba(120,53,15,.06);

    --tabbar-height: 56px;
    --banner-height: 36px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-body);
       background: var(--amber-50); color: var(--gray-700); line-height: 1.5; }

/* =========================================
   Site banner (all breakpoints)
   ========================================= */
.site-banner {
    background: var(--amber-800); color: var(--amber-100);
    text-align: center; padding: 8px 12px; font-family: var(--font-display);
    font-size: 17px; font-weight: 600; letter-spacing: .04em;
    position: sticky; top: 0; z-index: 60;
}

/* =========================================
   Layout — mobile-first
   ========================================= */
.layout {
    display: block;
    min-height: 100vh;
    padding-bottom: calc(var(--tabbar-height) + 8px);
}

/* =========================================
   Sidebar — hidden on mobile, restored at 768px+
   ========================================= */
.sidebar { display: none; }
.sidebar-header {
    padding: 20px 16px 12px;
    border-bottom: 1px solid var(--amber-700);
}
.logo { font-family: var(--font-display); font-size: 18px; font-weight: 600; color: #fff; }
.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-link {
    display: block;
    padding: 10px 16px;
    color: var(--amber-200);
    text-decoration: none;
    border-radius: 0;
    font-family: var(--font-body);
    font-size: 14px;
    transition: background .15s;
}
.nav-link:hover { background: var(--amber-700); color: #fff; }
.nav-link.active { background: var(--amber-600); color: #fff; font-weight: 600; }
.nav-new { color: var(--amber-300); margin-top: 8px; }
.nav-admin { color: var(--amber-300); margin-top: 8px; border-top: 1px solid var(--amber-700); padding-top: 12px; }
.nav-divider { border-top: 1px solid var(--amber-700); margin: 8px 16px; }
.nav-section-label {
    padding: 8px 16px 2px;
    font-family: var(--font-data);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--amber-500);
}
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--amber-700);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.display-name { font-size: 13px; color: var(--amber-200); }
.btn-logout {
    background: none;
    border: 1px solid var(--amber-600);
    color: var(--amber-200);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    min-height: 44px;
    font-size: 12px;
    cursor: pointer;
}
.btn-logout:hover { background: var(--amber-700); }

/* =========================================
   Mobile bottom tab bar (<768px)
   ========================================= */
.mobile-tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    display: flex;
    background: #fff;
    border-top: 1px solid var(--amber-100);
    box-shadow: 0 -2px 8px rgba(120,53,15,.08);
    height: var(--tabbar-height);
}
.mobile-tab {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px;
    min-height: 44px;
    font-family: var(--font-data);
    font-size: 10px; font-weight: 600;
    color: var(--gray-400);
    text-decoration: none;
}
.mobile-tab .tab-icon { font-size: 19px; line-height: 1; }
.mobile-tab.active { color: var(--amber-700); }

/* =========================================
   Main Content
   ========================================= */
.main-content { padding: 16px; }
.list-header { margin-bottom: 16px; }
.list-header h1 { font-family: var(--font-display); font-size: 22px; color: var(--amber-800); font-weight: 600; }

/* =========================================
   Item Table — table markup, card layout on mobile
   ========================================= */
.list-container { background: #fff; border-radius: var(--radius-lg);
                  box-shadow: var(--shadow-md); overflow: hidden; }
.item-table { width: 100%; border-collapse: collapse; }
.item-table thead th {
    background: var(--amber-100); padding: 10px 12px;
    text-align: left; font-family: var(--font-data);
    font-size: 12px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em; color: var(--amber-700);
}
.item-row td { padding: 10px 12px; border-bottom: 1px solid var(--amber-100); vertical-align: middle; }
.item-row:last-child td { border-bottom: none; }
.item-row.in-cart .item-name-text,
.item-row.in-cart .item-qty-text,
.item-row.in-cart .item-unit-text {
    text-decoration: line-through; color: var(--gray-400);
}
.item-check input[type=checkbox] {
    width: 22px; height: 22px; cursor: pointer;
    accent-color: var(--amber-600);
}
.item-name-text { font-family: var(--font-body); font-weight: 500; }
.item-qty-text, .item-unit-text { font-family: var(--font-data); font-size: 14px; color: var(--amber-700); font-variant-numeric: tabular-nums; }

/* Inline edit */
.inline-edit { display: none; }
.inline-edit.visible { display: block; }
.edit-name, .edit-qty { padding: 8px; min-height: 44px; border: 1px solid var(--amber-300);
                         border-radius: var(--radius-sm); font-size: 14px; }
.edit-name { width: 140px; }
.edit-qty { width: 70px; }
.edit-unit { padding: 8px; min-height: 44px; border: 1px solid var(--amber-300);
             border-radius: var(--radius-sm); font-size: 14px; }

.item-actions { display: flex; gap: 4px; }
.btn-icon { background: none; border: none; font-size: 17px; cursor: pointer; padding: 8px;
            min-width: 44px; min-height: 44px;
            border-radius: var(--radius-sm); transition: background .1s; }
.btn-icon:hover { background: var(--amber-100); }

/* Row check-off collapse animation */
.item-row.collapsing {
    transition: opacity .25s ease-in, transform .25s ease-in, max-height .25s ease-in;
    opacity: 0; transform: scale(.97);
}

/* WebSocket update pulse highlight (fires on rows updated by another user) */
@keyframes ws-pulse {
    0%   { background: var(--amber-100); }
    100% { background: transparent; }
}
.item-row.ws-pulse { animation: ws-pulse .8s ease-out; }

/* Swipe gesture affordance (touch feedback flash, see list_ui.js) */
.item-row.swipe-check { background: #dcfce7; transition: background .15s; }
.item-row.swipe-delete { background: #fee2e2; transition: background .15s; }

/* Card layout on mobile — table semantics kept, no template changes needed */
@media (max-width: 767px) {
    .item-table thead { display: none; }
    .item-table, .item-table tbody { display: block; width: 100%; }
    .item-row {
        display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px;
        padding: 4px 0;
    }
    .item-row td.item-check,
    .item-row td.item-name,
    .item-row td.item-qty,
    .item-row td.item-unit { display: contents; }
    .item-row td.item-actions { display: flex; width: 100%; justify-content: flex-end; gap: 4px; padding-top: 0; }
}

/* =========================================
   Add Item Form
   ========================================= */
.add-item-form { padding: 12px 16px; background: var(--amber-50);
                 border-top: 1px solid var(--amber-100); }
.add-item-fields { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.add-item-fields input, .add-item-fields select {
    padding: 10px 12px; min-height: 44px; border: 1px solid var(--amber-200);
    border-radius: var(--radius-sm); font-size: 14px;
}
.add-item-fields input[name=name] { flex: 1; min-width: 160px; }
.add-item-fields input[name=quantity] { width: 70px; }

@media (max-width: 767px) {
    .add-item-form {
        position: sticky; bottom: var(--tabbar-height);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: 0 -2px 8px rgba(120,53,15,.06);
    }
    .add-item-fields input[name=name] {
        border-radius: var(--radius-full);
    }
}

/* =========================================
   Buttons
   ========================================= */
.btn-primary {
    background: var(--amber-500); color: #fff; border: none;
    border-radius: var(--radius-sm); padding: 10px 18px; min-height: 44px;
    font-family: var(--font-body); font-size: 14px; font-weight: 600; cursor: pointer; transition: background .15s;
}
.btn-primary:hover { background: var(--amber-600); }
.btn-secondary {
    background: none; border: 1px solid var(--amber-400); color: var(--amber-700);
    border-radius: var(--radius-sm); padding: 10px 16px; min-height: 44px;
    font-family: var(--font-body); font-size: 14px; cursor: pointer; text-decoration: none;
    display: inline-flex; align-items: center;
}
.btn-secondary:hover { background: var(--amber-100); }
.btn-full { width: 100%; }
.btn-purchased {
    background: var(--amber-600); color: #fff; border: none;
    border-radius: var(--radius-sm); padding: 12px 20px; min-height: 44px;
    font-family: var(--font-body); font-size: 14px; font-weight: 600; cursor: pointer; transition: background .15s;
}
.btn-purchased:hover { background: var(--amber-700); }
.list-footer { padding: 12px 16px; }

/* Admin buttons */
.btn-approve { background: var(--green-500); color: #fff; border: none;
               border-radius: var(--radius-sm); padding: 8px 12px; min-height: 44px; cursor: pointer; font-size: 13px; }
.btn-reject  { background: var(--red-500);   color: #fff; border: none;
               border-radius: var(--radius-sm); padding: 8px 12px; min-height: 44px; cursor: pointer; font-size: 13px; }
.btn-unlock  { background: var(--amber-500); color: #fff; border: none;
               border-radius: var(--radius-sm); padding: 8px 12px; min-height: 44px; cursor: pointer; font-size: 13px; }

/* =========================================
   Auth Pages
   ========================================= */
.auth-page { display: flex; align-items: center; justify-content: center;
             min-height: 100vh; background: var(--amber-100); padding: 16px; }
.auth-card {
    background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
    padding: 32px 24px; width: 100%; max-width: 420px;
}
.auth-title { font-family: var(--font-display); font-size: 24px; font-weight: 600; color: var(--amber-700); margin-bottom: 8px; }
.auth-card h2 { font-family: var(--font-display); font-size: 18px; color: var(--amber-800); margin-bottom: 20px; }
.auth-link { margin-top: 16px; font-size: 14px; text-align: center; }
.auth-link a { color: var(--amber-600); text-decoration: none; }
.pending-icon { font-size: 48px; text-align: center; margin: 12px 0; }

/* =========================================
   Forms
   ========================================= */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600;
                    color: var(--amber-800); margin-bottom: 4px; }
.form-group input, .form-group select {
    width: 100%; padding: 11px 12px; min-height: 44px; border: 1px solid var(--amber-200);
    border-radius: var(--radius-sm); font-size: 14px; outline: none;
    transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus { border-color: var(--amber-500); }
.form-group textarea {
    width: 100%; padding: 11px 12px; border: 1px solid var(--amber-200);
    border-radius: var(--radius-sm); font-size: 14px; outline: none;
    transition: border-color .15s; resize: vertical;
}
.form-group textarea:focus { border-color: var(--amber-500); }
.form-check label { display: flex; align-items: center; gap: 8px; font-size: 14px;
                    font-weight: normal; color: var(--gray-700); cursor: pointer; }
.form-check input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--amber-600); }
.field-error { font-size: 12px; color: var(--red-500); margin-top: 4px; }
.form-card { background: #fff; border-radius: var(--radius-lg);
             box-shadow: var(--shadow-md); padding: 24px 20px; max-width: 400px; }

/* =========================================
   Alerts
   ========================================= */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 14px; }
.alert-error { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.empty-msg { color: var(--gray-400); font-style: italic; text-align: center; padding: 20px; }
.muted { color: var(--gray-400); font-size: 14px; padding: 8px 0; }

/* =========================================
   Admin Panel
   ========================================= */
.admin-section { margin-bottom: 32px; }
.admin-section h2 { font-family: var(--font-display); font-size: 17px; font-weight: 600; color: var(--amber-800);
                    margin-bottom: 12px; padding-bottom: 6px;
                    border-bottom: 2px solid var(--amber-200); }
.admin-table { width: 100%; border-collapse: collapse; background: #fff;
               border-radius: var(--radius-md); box-shadow: var(--shadow); overflow: hidden; }
.admin-table th { background: var(--amber-100); padding: 10px 12px;
                  text-align: left; font-family: var(--font-data); font-size: 12px; font-weight: 600;
                  text-transform: uppercase; color: var(--amber-700); }
.admin-table td { padding: 10px 12px; border-bottom: 1px solid var(--amber-50); font-size: 14px; }
.admin-table tr:last-child td { border-bottom: none; }

/* =========================================
   WS Reconnect Banner
   ========================================= */
.ws-banner {
    position: fixed; top: var(--banner-height); left: 0; right: 0; z-index: 55;
    background: var(--amber-400); color: var(--amber-900);
    text-align: center; padding: 8px; font-size: 13px; font-weight: 600;
    box-shadow: 0 2px 4px rgba(0,0,0,.15);
}
.hidden { display: none !important; }

/* =========================================
   Responsive — tablet & desktop (sidebar returns)
   ========================================= */
@media (min-width: 768px) {
    .layout {
        display: grid;
        grid-template-columns: 200px 1fr;
        min-height: 100vh;
        padding-bottom: 0;
    }
    .sidebar {
        display: flex;
        flex-direction: column;
        background: var(--amber-800);
        color: var(--amber-100);
    }
    .mobile-tabbar { display: none; }
    .main-content { padding: 20px 28px; max-width: 860px; }
    .add-item-form {
        position: static;
        border-radius: 0;
        box-shadow: none;
    }
    .add-item-fields input[name=name] { border-radius: var(--radius-sm); }

    .item-table thead { display: table-header-group; }
    .item-table, .item-table tbody { display: table; }
    .item-row { display: table-row; }
    .item-row td { display: table-cell; }
    .item-actions { width: auto; justify-content: flex-start; }
}

@media (min-width: 1024px) {
    .layout { grid-template-columns: 220px 1fr; }
    .main-content { padding: 24px 32px; }
}
