/* ===== Client Portal Styles — Enhanced ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Poppins:wght@500;600;700&display=swap');

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #243048;
    --primary-light: #2e3d5c;
    --primary-dark: #1a2336;
    --primary-50: #EEF4FA;
    --accent: #243048;
    --accent-light: #EEF4FA;
    --accent-dark: #1a2336;
    --success: #10b981;
    --success-light: #d1fae5;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --bg: #EEF4FA;
    --bg-alt: #f6fafd;
    --card: #FFFFFF;
    --text: #243048;
    --text-muted: #5b6880;
    --border: #d6e6f5;
    --border-light: #EEF4FA;
    --radius: 10px;
    --radius-lg: 16px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 6px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-xl: 0 10px 15px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.04);
    --transition: 0.15s ease;
    --sky: #A3CDEF;
    --sky-soft: rgba(163,205,239,0.28);
    --text-secondary: #4a5770;
    --card-hover: #f6fafd;
    --info: #3d7fbf;
    --info-light: #e3f0fb;
    --radius-sm: 7px;
    --radius-xl: 22px;
    --font-heading: 'Poppins', 'Inter', sans-serif;
}

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.02em; }

/* ── Header ────────────────────────────────────────────── */
.portal-header {
    background: #243048;
    color: white;
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    gap: 1rem;
}

.portal-logo {
    font-family: 'Inter', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    color: white;
    text-decoration: none;
    flex-shrink: 0;
    letter-spacing: -0.03em;
}

.portal-logo span { color: var(--accent); }

/* ── User pill ──────────────────────────────────────────── */
.user-pill {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: rgba(255,255,255,0.1);
    border-radius: 30px;
    padding: 0.25rem 0.35rem 0.25rem 0.8rem;
    flex-shrink: 0;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.08);
}

.user-pill-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.2;
}

.user-pill-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: white;
    text-decoration: none;
    white-space: nowrap;
}

.user-pill-name:hover { text-decoration: underline; }

.user-pill-email {
    font-size: 0.68rem;
    color: rgba(255,255,255,0.55);
    white-space: nowrap;
}

.logout-btn {
    background: rgba(255,255,255,0.18);
    color: white;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 20px;
    padding: 0.28rem 0.7rem;
    font-size: 0.78rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    font-family: inherit;
}

.logout-btn:hover {
    background: rgba(255,255,255,0.3);
    border-color: rgba(255,255,255,0.2);
}

/* ── Nav tabs ─────────────────────────────────────────── */
.portal-nav {
    background: white;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.nav-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    gap: 0;
}

.nav-tab {
    display: block;
    padding: 0.85rem 1.25rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: var(--transition);
    position: relative;
}

.nav-tab::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 1.25rem;
    right: 1.25rem;
    height: 2px;
    background: var(--primary);
    transform: scaleX(0);
    transition: transform var(--transition);
}

.nav-tab:hover {
    color: var(--primary);
}

.nav-tab:hover::after {
    transform: scaleX(1);
}

.nav-tab.active {
    color: var(--primary);
    font-weight: 600;
}

.nav-tab.active::after {
    transform: scaleX(1);
}

/* ── Main content ────────────────────────────────────── */
.portal-main {
    max-width: 1400px;
    margin: 1.5rem auto;
    padding: 0 1.5rem;
    flex: 1;
    width: 100%;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-header h1 {
    font-size: 1.5rem;
    color: var(--primary);
    font-weight: 700;
}

/* ── KPI cards ──────────────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.85rem;
    margin-bottom: 1.25rem;
}

.kpi-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.9rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    border: 1px solid var(--border);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-light), var(--accent));
    opacity: 0;
    transition: var(--transition);
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.kpi-card:hover::before {
    opacity: 1;
}

.kpi-card span {
    font-size: 0.76rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.kpi-card strong {
    font-size: 1.4rem;
    color: var(--primary);
    word-break: break-word;
    font-weight: 700;
}

/* ── Cards / sections ────────────────────────────────── */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.15rem 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    overflow: hidden;
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.card-title {
    font-size: 1.05rem;
    color: var(--primary);
    margin-bottom: 0.75rem;
    font-weight: 700;
}

/* ── Booking cards ───────────────────────────────────── */
.booking-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary-light);
    cursor: pointer;
    transition: var(--transition);
}

.booking-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.booking-card--pending    { border-left-color: var(--warning); }
.booking-card--confirmed  { border-left-color: var(--primary-light); }
.booking-card--inprogress { border-left-color: var(--accent); }
.booking-card--completed  { border-left-color: var(--success); }
.booking-card--cancelled  { border-left-color: #9e9e9e; opacity: 0.7; }

/* A request in the list is a link to its page: it keeps the card's look */
.request-card { display: block; color: inherit; text-decoration: none; }

.booking-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.booking-card__title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
}

.booking-card__meta {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    line-height: 1.5;
}

.booking-card__footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* ── Tables ──────────────────────────────────────────── */
.portal-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
    display: block;
    overflow-x: auto;
}

@media (min-width: 700px) {
    .portal-table { display: table; }
}

.portal-table thead {
    background: linear-gradient(135deg, var(--primary-50), #f0f2fd);
}

.portal-table th {
    text-align: left;
    padding: 0.65rem 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary-light);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    border-bottom: 2px solid var(--border);
}

.portal-table td {
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--border-light);
    font-size: 0.85rem;
    vertical-align: middle;
    transition: var(--transition);
}

.portal-table tbody tr:hover {
    background: #f8f9fd;
}

.portal-table tbody tr {
    cursor: pointer;
}

/* ── Badges ────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: capitalize;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.badge-pending      { background: var(--warning-light); color: #f57f17; }
.badge-confirmed    { background: #e3f2fd; color: #1565c0; }
.badge-inprogress   { background: var(--accent-light); color: #006064; }
.badge-completed    { background: var(--success-light); color: var(--success); }
.badge-cancelled    { background: var(--danger-light); color: #c62828; }
.badge-draft        { background: #ede7f6; color: #4527a0; }
.badge-sent         { background: #e3f2fd; color: #1565c0; }
.badge-partiallypaid { background: #fff3e0; color: #ef6c00; }
.badge-paid         { background: var(--success-light); color: var(--success); }
.badge-overdue      { background: var(--danger-light); color: #c62828; }
.badge-writtenoff   { background: #eeeeee; color: #616161; }
.badge-active       { background: var(--success-light); color: var(--success); }
.badge-inactive     { background: #f5f5f5; color: #888; }

/* The customer's request statuses (portal_request_status_*); cancelled reuses .badge-cancelled */
.badge-preparing       { background: #ede7f6; color: #4527a0; }
.badge-awaiting_answer { background: var(--warning-light); color: #e65100; }
.badge-expired         { background: #eeeeee; color: #616161; }
.badge-declined        { background: var(--danger-light); color: #c62828; }
.badge-booked          { background: var(--success-light); color: var(--success); }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.4rem 1rem;
    border: none;
    border-radius: 6px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
    white-space: nowrap;
    font-family: inherit;
    box-shadow: 0 2px 8px rgba(57,73,171,0.2);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(57,73,171,0.3);
}

.btn:active {
    transform: translateY(0);
}

.btn-sm {
    padding: 0.28rem 0.65rem;
    font-size: 0.78rem;
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--border);
    box-shadow: none;
}

.btn-outline:hover {
    border-color: var(--primary-light);
    background: #f0f2fd;
    box-shadow: none;
}

.btn-success {
    background: linear-gradient(135deg, #388e3c, var(--success));
    box-shadow: 0 2px 8px rgba(67,160,71,0.25);
}

.btn-success:hover {
    box-shadow: 0 4px 14px rgba(67,160,71,0.35);
}

.btn-danger {
    background: linear-gradient(135deg, #c62828, var(--danger));
    box-shadow: 0 2px 8px rgba(229,57,53,0.25);
}

.btn-danger:hover {
    box-shadow: 0 4px 14px rgba(229,57,53,0.35);
}

.link {
    color: var(--primary-light);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
}

.link:hover {
    color: var(--primary);
    text-decoration: underline;
}

/* ── Alerts ──────────────────────────────────────────── */
.alert {
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm, 6px);
    margin-bottom: 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.alert-info    { background: #e3f2fd; color: #1565c0; border-color: #90caf9; }
.alert-success { background: var(--success-light); color: #2e7d32; border-color: #a5d6a7; }
.alert-danger  { background: var(--danger-light); color: #c62828; border-color: #ef9a9a; }
.alert-warning { background: var(--warning-light); color: #e65100; border-color: #ffe082; }

/* A message whose container is off screen (the page is scrolled) floats under the header. It is fixed, so it takes no
   room in the page and nothing moves; a click closes it (showAlert in portal-common.js). */
.alert-floating {
    position: fixed;
    top: 4.5rem; /* the sticky header is 60px high */
    left: 1rem;
    right: 1rem;
    max-width: 720px;
    margin: 0 auto;
    z-index: 1300; /* above the header (200) and the dialogs (1000) */
    box-shadow: var(--shadow-xl);
    overflow-wrap: anywhere;
    cursor: pointer;
}

@media print {
    .alert-floating { display: none; }
}

/* The fade-in of .portal-main > * must not reach the message containers: a fixed alert inside a box that is being
   animated (transformed) is placed relative to that box, not to the window. */
.portal-main > #error-container,
.portal-main > #success-container { animation: none; }

/* ── Forms ───────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.3rem;
}

.form-input {
    width: 100%;
    padding: 0.55rem 0.8rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.92rem;
    font-family: inherit;
    color: var(--text);
    background: white;
    outline: none;
    transition: var(--transition);
}

.form-input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(57,73,171,0.1);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ── Detail sections ──────────────────────────────────── */
.detail-grid {
    display: grid;
    gap: 0.75rem;
}

.detail-grid.two-col {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.85rem;
}

.detail-row:last-child { border-bottom: none; }

.detail-row span:first-child {
    color: var(--text-muted);
    font-weight: 500;
}

.detail-row span:last-child {
    font-weight: 600;
    text-align: right;
}

/* ── Invoice-specific ─────────────────────────────────── */
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}

.invoice-total {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}

/* ── Modal ───────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-panel {
    background: white;
    border-radius: var(--radius-lg);
    width: min(500px, 95vw);
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.5rem;
    box-shadow: var(--shadow-xl);
}

/* ── Login page ──────────────────────────────────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
    padding: 1.5rem;
}

.login-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: 2.25rem 2rem;
    width: 100%;
    max-width: 420px;
}

.login-card h1 {
    font-family: 'Inter', sans-serif;
    color: var(--primary);
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.35rem;
}

.login-card p {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-bottom: 1.5rem;
}

/* ── Profile ─────────────────────────────────────────── */
.profile-avatar {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 1rem;
    box-shadow: 0 4px 12px rgba(57,73,171,0.3);
}

/* ── Empty state ─────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

/* ── Footer ──────────────────────────────────────────── */
.portal-footer {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: rgba(255,255,255,0.5);
    text-align: center;
    padding: 1rem;
    font-size: 0.78rem;
    margin-top: auto;
}

/* ── Animations ──────────────────────────────────────── */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.portal-main > * {
    animation: fadeInUp 0.3s ease;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 768px) {
    .form-row { grid-template-columns: 1fr; }
    .nav-tab { padding: 0.65rem 0.75rem; font-size: 0.82rem; }
    .header-inner { padding: 0 1rem; }
    .portal-main { padding: 0 1rem; margin: 1rem auto; }
}

@media (max-width: 480px) {
    .user-pill-info { display: none; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Language Switcher ──────────────────────────── */
#lang-switcher {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: 0.5rem;
}
.lang-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.6);
    padding: 0.15rem 0.45rem;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 3px;
    transition: 0.15s;
    font-family: inherit;
    line-height: 1.4;
}
.lang-btn:hover { background: rgba(255,255,255,0.1); color: white; }
.lang-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.header-right #lang-switcher .lang-btn { border-color: var(--border); color: var(--text-muted); }
.header-right #lang-switcher .lang-btn.active { color: white; }

/* ===== Chistify brand ===== */
h1, h2, h3, h4, .serif, .page-title, .section-title, .stat-value {
    font-family: var(--font-heading);
    letter-spacing: -0.02em;
}
::selection { background: #243048; color: #A3CDEF; }
.brand-logo { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-heading); font-weight: 700; text-decoration: none; }
.brand-logo svg { width: 34px; height: 34px; flex-shrink: 0; }

.portal-logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-heading);
    font-weight: 700;
    letter-spacing: -0.02em;
}
.portal-logo::before {
    content: '';
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cg fill='none' stroke='%23A3CDEF' stroke-width='6' stroke-linecap='round'%3E%3Ccircle cx='50' cy='50' r='44'/%3E%3Cpath d='M50 22C50 22 63 42 63 52A13 13 0 0 1 37 52C37 42 50 22 50 22Z'/%3E%3Cpath d='M20 72C30 60 40 84 50 72C60 60 70 84 80 72'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
}

.portal-header { border-bottom: 1px solid var(--sky-soft); box-shadow: none; }
.login-page .portal-logo { display: flex !important; justify-content: center; color: var(--accent) !important; }
.login-page .portal-logo::before { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cg fill='none' stroke='%23243048' stroke-width='6' stroke-linecap='round'%3E%3Ccircle cx='50' cy='50' r='44'/%3E%3Cpath d='M50 22C50 22 63 42 63 52A13 13 0 0 1 37 52C37 42 50 22 50 22Z'/%3E%3Cpath d='M20 72C30 60 40 84 50 72C60 60 70 84 80 72'/%3E%3C/g%3E%3C/svg%3E"); }
.login-card { border-radius: var(--radius-xl); border: 1.5px solid var(--border); }
.btn-primary { border-radius: 10px; font-weight: 700; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent) !important; box-shadow: 0 0 0 3px var(--sky-soft); }
