/* =========================================================
   Pelícanos - Admin Panel
   ========================================================= */

:root {
    --cream: #F3E9CF;
    --cream-soft: #FAF3E0;
    --cream-dark: #E8DCBA;
    --teal: #2D7A6F;
    --teal-dark: #1F5850;
    --teal-light: #4A9E90;
    --gold: #C9A55B;
    --gold-dark: #A38338;
    --red: #C4452C;
    --red-dark: #A13820;
    --green: #4BA85A;
    --text: #2A2A28;
    --text-muted: #6B6358;
    --border: rgba(45, 122, 111, 0.18);
    --border-strong: rgba(45, 122, 111, 0.35);
    --shadow-sm: 0 2px 6px rgba(45, 50, 40, 0.06);
    --shadow-md: 0 6px 18px rgba(45, 50, 40, 0.1);
    --shadow-lg: 0 20px 60px rgba(45, 50, 40, 0.2);
    --radius: 8px;
    --radius-lg: 14px;

    --font-serif: 'Playfair Display', Georgia, serif;
    --font-sans: 'Lato', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body {
    font-family: var(--font-sans);
    color: var(--text);
    background: #F8F4E8;
    min-height: 100vh;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

/* ============= LOGIN ============= */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
    background: linear-gradient(135deg, var(--cream) 0%, var(--cream-soft) 100%);
}

.login-card {
    background: white;
    padding: 2.5rem 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    border-top: 4px solid var(--teal);
}
.login-brand {
    text-align: center;
    margin-bottom: 1.75rem;
}
.login-logo {
    max-width: 180px;
    height: auto;
    margin: 0 auto 0.25rem;
    display: block;
}
.login-brand h1 {
    font-family: var(--font-serif);
    font-size: 2.2rem;
    color: var(--teal);
    margin-bottom: 0.25rem;
}
.login-brand p {
    color: var(--gold-dark);
    font-size: 0.85rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    font-weight: 700;
}

.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-form label { display: flex; flex-direction: column; gap: 0.35rem; }
.login-form label span {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
}
.login-form input {
    padding: 0.7rem 0.9rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    background: var(--cream-soft);
    transition: all 0.2s;
}
.login-form input:focus {
    outline: none;
    border-color: var(--teal);
    background: white;
    box-shadow: 0 0 0 3px rgba(45, 122, 111, 0.12);
}
.login-footer { text-align: center; margin-top: 1.25rem; font-size: 0.85rem; }
.login-footer a { color: var(--text-muted); text-decoration: none; }
.login-footer a:hover { color: var(--teal); }

/* ============= ALERTS ============= */
.alert {
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-error {
    background: rgba(196, 69, 44, 0.1);
    color: var(--red-dark);
    border: 1px solid rgba(196, 69, 44, 0.2);
}
.alert-success {
    background: rgba(75, 168, 90, 0.12);
    color: #2E7A3C;
    border: 1px solid rgba(75, 168, 90, 0.25);
}

/* ============= BUTTONS ============= */
.btn-primary, .btn-secondary, .btn-link, .btn-icon, .btn-danger {
    font-family: var(--font-sans);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: var(--radius);
    border: none;
    font-size: 0.88rem;
}
.btn-primary {
    background: var(--teal);
    color: white;
    padding: 0.7rem 1.25rem;
}
.btn-primary:hover { background: var(--teal-dark); transform: translateY(-1px); }
.btn-secondary {
    background: var(--cream-dark);
    color: var(--text);
    padding: 0.7rem 1.25rem;
}
.btn-secondary:hover { background: #D8CCA8; }
.btn-danger {
    background: var(--red);
    color: white;
    padding: 0.7rem 1.25rem;
}
.btn-danger:hover { background: var(--red-dark); }

.btn-link {
    background: transparent;
    color: var(--text);
    padding: 0.45rem 0.85rem;
    text-decoration: none;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.btn-link:hover { background: var(--cream-dark); color: var(--teal); }
.btn-link.danger { color: var(--red); }
.btn-link.danger:hover { background: rgba(196, 69, 44, 0.12); }

.btn-icon {
    background: transparent;
    color: var(--text-muted);
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius);
    font-size: 0.95rem;
}
.btn-icon:hover { background: var(--cream-dark); color: var(--teal); }
.btn-icon.danger:hover { background: rgba(196, 69, 44, 0.12); color: var(--red); }

/* ============= ADMIN HEADER ============= */
.admin-header {
    background: var(--teal-dark);
    color: white;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}
.admin-header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.9rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}
.admin-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.admin-brand-logo {
    height: 36px;
    width: auto;
    display: block;
    filter: brightness(0) invert(1);
    opacity: 0.95;
}
.admin-brand h1 {
    font-family: var(--font-serif);
    font-size: 1.3rem;
    display: inline;
    color: white;
}
.admin-brand span {
    color: var(--gold);
    font-size: 0.7rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    margin-left: 0.5rem;
    font-weight: 700;
}
.admin-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
}
.admin-nav .btn-link { color: white; }
.admin-nav .btn-link:hover { background: rgba(255, 255, 255, 0.08); color: var(--gold); }
.admin-nav .btn-link.danger { color: #FFB4A8; }
.admin-nav .btn-link.danger:hover { background: rgba(255, 180, 168, 0.1); color: white; }

.user-badge {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    margin-right: 0.5rem;
}

/* ============= TABS ============= */
.admin-tabs {
    background: white;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: sticky;
    top: 62px;
    z-index: 40;
}
.admin-tabs-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    gap: 0.25rem;
    min-width: max-content;
}
.admin-tab {
    background: transparent;
    border: none;
    padding: 1rem 1.25rem;
    font-family: var(--font-sans);
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
.admin-tab:hover { color: var(--teal); background: var(--cream-soft); }
.admin-tab.active {
    color: var(--teal);
    border-bottom-color: var(--teal);
}
.admin-tab .badge {
    background: var(--cream-dark);
    color: var(--text-muted);
    font-size: 0.72rem;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-weight: 700;
}
.admin-tab.active .badge { background: var(--teal); color: white; }

/* ============= MAIN ============= */
.admin-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

.loading-admin {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
}
.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--cream-dark);
    border-top-color: var(--teal);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============= MENU EDITOR ============= */
.menu-editor-head {
    background: white;
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-lg);
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.menu-editor-head h2 {
    font-family: var(--font-serif);
    color: var(--teal);
    font-size: 1.4rem;
}
.menu-meta {
    font-size: 0.82rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.menu-status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}
.menu-status-chip.active { background: rgba(75, 168, 90, 0.15); color: #2E7A3C; }
.menu-status-chip.inactive { background: rgba(196, 69, 44, 0.12); color: var(--red-dark); }
.menu-status-chip .dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: currentColor;
}
.menu-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ============= CATEGORIES ============= */
.cat-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 1rem;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.cat-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background: var(--cream-soft);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    gap: 1rem;
    flex-wrap: wrap;
}
.cat-head:hover { background: var(--cream-dark); }
.cat-title {
    font-family: var(--font-serif);
    font-size: 1.1rem;
    color: var(--teal);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.cat-toggle { font-size: 0.8rem; color: var(--text-muted); transition: transform 0.2s; }
.cat-card.collapsed .cat-toggle { transform: rotate(-90deg); }
.cat-card.collapsed .cat-body { display: none; }

.cat-count {
    font-size: 0.78rem;
    color: var(--text-muted);
    background: white;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-weight: 700;
}
.cat-actions {
    display: flex;
    gap: 0.25rem;
}

.cat-body { padding: 0.5rem 1.25rem 1rem; }

/* ============= ITEM ROWS ============= */
.item-row {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    gap: 0.75rem;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px dashed var(--border);
}
.item-row:last-child { border-bottom: none; }

.item-info { min-width: 0; }
.item-info-name {
    font-weight: 700;
    color: var(--text);
    font-size: 0.95rem;
    margin-bottom: 0.2rem;
}
.item-info-name-en {
    color: var(--text-muted);
    font-size: 0.82rem;
    font-style: italic;
    margin-left: 0.35rem;
    font-weight: 400;
}
.item-info-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}
.item-allergens-mini {
    display: flex;
    gap: 0.2rem;
    margin-top: 0.3rem;
    flex-wrap: wrap;
}
.item-allergens-mini .chip {
    background: var(--cream-dark);
    padding: 0.08rem 0.4rem;
    border-radius: 999px;
    font-size: 0.68rem;
    color: var(--text-muted);
}

.item-price-cell {
    font-weight: 700;
    color: var(--gold-dark);
    font-size: 0.92rem;
    white-space: nowrap;
}

.toggle-available {
    position: relative;
    width: 36px;
    height: 20px;
    background: #CCC;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s;
    border: none;
    padding: 0;
    flex-shrink: 0;
}
.toggle-available::after {
    content: '';
    position: absolute;
    left: 2px; top: 2px;
    width: 16px; height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}
.toggle-available.on { background: var(--green); }
.toggle-available.on::after { transform: translateX(16px); }

.item-actions {
    display: flex;
    gap: 0.15rem;
}

/* ============= ADD ROW ============= */
.add-item-btn {
    display: block;
    width: 100%;
    padding: 0.6rem;
    background: transparent;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.85rem;
    margin-top: 0.5rem;
    transition: all 0.2s;
}
.add-item-btn:hover {
    background: var(--cream-soft);
    border-color: var(--teal);
    color: var(--teal);
}

.add-cat-wrap { text-align: center; margin-top: 1.5rem; }

/* ============= MODAL ============= */
.modal[hidden] { display: none !important; }
.modal {
    position: fixed;
    inset: 0;
    background: rgba(30, 35, 30, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
    background: white;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 640px;
    max-height: 92vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.25s ease;
}
.modal-card.modal-sm { max-width: 420px; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--cream-soft);
    flex-shrink: 0;
}
.modal-head h3 {
    font-family: var(--font-serif);
    color: var(--teal);
    font-size: 1.15rem;
}
.modal-close {
    background: transparent;
    border: none;
    font-size: 1.1rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.35rem 0.6rem;
    border-radius: var(--radius);
}
.modal-close:hover { background: var(--cream-dark); color: var(--red); }

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
    padding-top: 1rem;
}

/* ============= FORMS ============= */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}
.modal-body label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.modal-body label span {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
}
.modal-body label small {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-top: 0.1rem;
}
.modal-body input[type="text"],
.modal-body input[type="password"],
.modal-body input[type="time"],
.modal-body input[type="file"],
.modal-body textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    background: var(--cream-soft);
    transition: all 0.2s;
    resize: vertical;
}
.modal-body input:focus,
.modal-body textarea:focus {
    outline: none;
    border-color: var(--teal);
    background: white;
    box-shadow: 0 0 0 3px rgba(45, 122, 111, 0.12);
}

.modal-body label.checkbox {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}
.modal-body label.checkbox input { width: 18px; height: 18px; cursor: pointer; }
.modal-body label.checkbox span { font-weight: 400; color: var(--text); font-size: 0.9rem; }

.modal-body fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
}
.modal-body fieldset legend {
    padding: 0 0.5rem;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
}

.allergen-picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.4rem;
    margin-top: 0.25rem;
}
.allergen-pick {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.6rem;
    background: var(--cream-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.82rem;
    transition: all 0.15s;
}
.allergen-pick:hover { background: var(--cream-dark); }
.allergen-pick input { margin: 0; cursor: pointer; }
.allergen-pick.checked {
    background: rgba(45, 122, 111, 0.12);
    border-color: var(--teal);
    color: var(--teal-dark);
    font-weight: 700;
}

.warn {
    background: rgba(201, 165, 91, 0.15);
    border-left: 3px solid var(--gold);
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--gold-dark);
}

/* ============= TOAST ============= */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    background: var(--teal-dark);
    color: white;
    padding: 0.7rem 1rem;
    border-radius: var(--radius);
    font-size: 0.88rem;
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    animation: toastIn 0.25s ease;
    max-width: 340px;
}
.toast.error { background: var(--red-dark); }
.toast.success { background: #2E7A3C; }
@keyframes toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: none; opacity: 1; }
}

/* ============= ALLERGENS MANAGER ============= */
.admin-tab-allergens { border-left: 1px solid var(--border); margin-left: 0.5rem; padding-left: 1rem; }
.allergens-info {
    background: var(--cream-soft);
    border: 1px solid var(--border);
    border-left: 3px solid var(--gold);
    border-radius: var(--radius);
    padding: 0.9rem 1.1rem;
    margin-bottom: 1.5rem;
    color: var(--text-muted);
    font-size: 0.88rem;
}
.allergens-info p { margin: 0; }

.allergens-manager {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.75rem;
}
.allergen-manage-item {
    background: var(--cream-soft);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    transition: all 0.2s;
}
.allergen-manage-item:hover {
    border-color: var(--teal-light);
}
.allergen-manage-head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.allergen-preview {
    width: 44px; height: 44px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
    overflow: hidden;
}
.allergen-preview img {
    width: 100%; height: 100%;
    object-fit: contain;
}
.allergen-preview.has-custom {
    background: rgba(45, 122, 111, 0.06);
    border-color: var(--teal);
}
.allergen-manage-name {
    font-weight: 700;
    color: var(--text);
    font-size: 0.92rem;
    flex: 1;
    min-width: 0;
}
.allergen-manage-status {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.allergen-manage-status.custom { color: var(--teal); font-weight: 700; }
.allergen-manage-actions {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}
.allergen-upload-btn {
    flex: 1;
    background: var(--teal);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 0.45rem 0.7rem;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}
.allergen-upload-btn:hover { background: var(--teal-dark); }
.allergen-upload-btn input { display: none; }
.allergen-upload-btn.busy { opacity: 0.6; cursor: wait; }
.allergen-remove-btn {
    background: transparent;
    color: var(--red);
    border: 1.5px solid var(--red);
    border-radius: var(--radius);
    padding: 0.4rem 0.6rem;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-sans);
}
.allergen-remove-btn:hover { background: var(--red); color: white; }
.allergen-remove-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
@media (max-width: 720px) {
    .admin-header-inner { padding: 0.7rem 1rem; }
    .admin-brand h1 { font-size: 1.1rem; }
    .admin-nav .btn-link { padding: 0.4rem 0.6rem; font-size: 0.82rem; }
    .user-badge { display: none; }
    .admin-tabs-inner { padding: 0 1rem; }
    .admin-main { padding: 1rem; }
    .menu-editor-head { padding: 1rem; }
    .menu-editor-head h2 { font-size: 1.2rem; }
    .item-row {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    .item-price-cell { font-size: 1rem; }
    .form-row { grid-template-columns: 1fr; }
    .allergen-picker { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
    .admin-tabs { top: 110px; }
    .admin-header { position: static; }
}
