/* ============================================================
   RIAD MARRAKECH — Premium Moroccan Design System
   Fonts: Cormorant Garamond (display) + Outfit (UI)
   ============================================================ */

/* --- Google Fonts fallback --- */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,600;1,400&family=Outfit:wght@300;400;500;600;700&display=swap');

/* --- Design Tokens --- */
:root {
    /* Moroccan Palette */
    --terracotta:       #C1613A;
    --terracotta-deep:  #A34A27;
    --terracotta-light: #E8896B;
    --terracotta-ghost: rgba(193, 97, 58, 0.08);

    --olive:            #5C6B3A;
    --olive-deep:       #404D28;
    --olive-light:      #8FA060;
    --olive-ghost:      rgba(92, 107, 58, 0.08);

    --sand:             #F5EDD8;
    --sand-warm:        #EDE0C0;
    --sand-deep:        #D6C9A8;
    --sand-dark:        #8A7A5E;

    --gold:             #C89B3C;
    --gold-light:       #E6C46A;

    --ink:              #2A2118;
    --ink-soft:         #4A3D2E;
    --ink-muted:        #7A6B56;

    /* Glass */
    --glass-bg:         rgba(255, 252, 245, 0.55);
    --glass-border:     rgba(200, 155, 60, 0.2);
    --glass-blur:       16px;

    /* Shadows */
    --shadow-sm:        0 2px 8px rgba(42, 33, 24, 0.08);
    --shadow-md:        0 8px 32px rgba(42, 33, 24, 0.12);
    --shadow-lg:        0 20px 60px rgba(42, 33, 24, 0.16);
    --shadow-terracotta: 0 8px 32px rgba(193, 97, 58, 0.25);

    /* Typography */
    --font-display:     'Cormorant Garamond', 'Georgia', serif;
    --font-ui:          'Outfit', 'Segoe UI', sans-serif;

    /* Radius */
    --radius-sm:        8px;
    --radius-md:        16px;
    --radius-lg:        24px;
    --radius-xl:        32px;

    /* Transitions */
    --ease:             cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-in:          cubic-bezier(0.4, 0, 1, 1);
    --ease-out:         cubic-bezier(0, 0, 0.2, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-ui);
    background-color: var(--sand);
    color: var(--ink);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
}

/* --- Decorative Background --- */
.bg-pattern {
    position: fixed;
    inset: 0;
    z-index: 0;
    background-image:
        radial-gradient(circle at 20% 20%, rgba(193, 97, 58, 0.06) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(92, 107, 58, 0.06) 0%, transparent 50%);
    pointer-events: none;
}

/* Moroccan star pattern using CSS */
.bg-pattern::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 59px,
            rgba(200, 155, 60, 0.04) 59px,
            rgba(200, 155, 60, 0.04) 60px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 59px,
            rgba(200, 155, 60, 0.04) 59px,
            rgba(200, 155, 60, 0.04) 60px
        );
    pointer-events: none;
}

.bg-glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    pointer-events: none;
    z-index: 0;
}

.bg-glow-1 {
    width: 500px; height: 500px;
    top: -150px; left: -150px;
    background: radial-gradient(circle, rgba(193, 97, 58, 0.12) 0%, transparent 70%);
}

.bg-glow-2 {
    width: 400px; height: 400px;
    bottom: -100px; right: -100px;
    background: radial-gradient(circle, rgba(92, 107, 58, 0.10) 0%, transparent 70%);
}

/* --- Header --- */
.header {
    position: relative;
    z-index: 10;
    padding: clamp(24px, 5vw, 48px) clamp(16px, 4vw, 48px) clamp(20px, 4vw, 40px);
    text-align: center;
    background: linear-gradient(
        180deg,
        rgba(245, 237, 216, 0.98) 0%,
        rgba(237, 224, 192, 0.95) 100%
    );
    border-bottom: 1px solid var(--sand-deep);
    backdrop-filter: blur(8px);
}

.header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        -45deg,
        transparent 0px,
        transparent 8px,
        rgba(200, 155, 60, 0.03) 8px,
        rgba(200, 155, 60, 0.03) 9px
    );
    pointer-events: none;
}

.header-inner {
    position: relative;
    max-width: 800px;
    margin: 0 auto;
}

.header-ornament {
    color: var(--gold);
    width: 120px;
    margin: 0 auto 8px;
    opacity: 0.7;
}

.header h1 {
    font-family: var(--font-display);
    font-size: clamp(1.6rem, 5vw, 2.8rem);
    font-weight: 600;
    color: var(--terracotta-deep);
    line-height: 1.15;
    letter-spacing: -0.01em;
    margin-bottom: 4px;
}

.header-subtitle {
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(1rem, 3vw, 1.3rem);
    color: var(--gold);
    letter-spacing: 0.08em;
    margin-bottom: 12px;
}

.authors {
    font-size: clamp(0.78rem, 2.2vw, 0.9rem);
    color: var(--ink-soft);
    font-weight: 500;
    letter-spacing: 0.03em;
    margin-bottom: 4px;
}

.supervisors {
    font-size: clamp(0.72rem, 2vw, 0.82rem);
    color: var(--ink-muted);
    font-style: italic;
}

/* --- Tabs --- */
.tabs {
    position: relative;
    z-index: 10;
    display: flex;
    background: var(--sand-warm);
    border-bottom: 1px solid var(--sand-deep);
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
    flex: 1;
    min-width: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    border: none;
    background: transparent;
    color: var(--ink-muted);
    font-family: var(--font-ui);
    font-weight: 500;
    font-size: clamp(0.78rem, 2.2vw, 0.9rem);
    cursor: pointer;
    transition: all 0.3s var(--ease-out);
    position: relative;
    white-space: nowrap;
}

.tab-btn::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 2px;
    background: var(--terracotta);
    transform: scaleX(0);
    transition: transform 0.3s var(--ease-out);
    transform-origin: center;
}

.tab-btn:hover {
    color: var(--terracotta);
    background: rgba(193, 97, 58, 0.05);
}

.tab-btn.active {
    color: var(--terracotta-deep);
    background: rgba(193, 97, 58, 0.06);
    font-weight: 600;
}

.tab-btn.active::after {
    transform: scaleX(1);
}

.tab-num {
    font-family: var(--font-display);
    font-size: 1.1em;
    color: var(--gold);
    font-style: italic;
}

.tab-label {
    letter-spacing: 0.02em;
}

/* --- Content Layout --- */
.content {
    flex: 1;
    position: relative;
    z-index: 5;
}

.tab-content {
    display: none;
    width: 100%;
}

.tab-content.active {
    display: flex;
}

/* --- Left Panel --- */
.panel-left {
    width: 400px;
    min-width: 400px;
    padding: clamp(16px, 3vw, 28px);
    overflow-y: auto;
    border-right: 1px solid var(--sand-deep);
    background: rgba(245, 237, 216, 0.6);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel-left::-webkit-scrollbar {
    width: 4px;
}
.panel-left::-webkit-scrollbar-track {
    background: transparent;
}
.panel-left::-webkit-scrollbar-thumb {
    background: var(--sand-deep);
    border-radius: 4px;
}

/* --- Section Badge --- */
.section-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 14px;
    background: var(--terracotta);
    color: white;
    font-family: var(--font-display);
    font-style: italic;
    font-size: 0.85rem;
    letter-spacing: 0.06em;
    border-radius: 100px;
    width: fit-content;
}

.panel-left h2 {
    font-family: var(--font-display);
    font-size: clamp(1.3rem, 4vw, 1.6rem);
    font-weight: 600;
    color: var(--ink);
    line-height: 1.2;
    margin-top: -4px;
}

/* --- Glass Cards --- */
.card-glass {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.3s var(--ease-out);
}

.card-glass:hover {
    box-shadow: var(--shadow-md);
}

.card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-ui);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--olive);
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(200, 155, 60, 0.15);
}

.card-title-icon {
    font-style: normal;
    font-size: 1rem;
}

/* --- Form Groups --- */
.form-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    font-size: 0.88rem;
    color: var(--ink-soft);
    font-weight: 400;
    line-height: 1.3;
    flex: 1;
}

/* --- Input Wrap --- */
.input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrap input[type="number"] {
    width: 88px;
    padding: 9px 12px;
    padding-right: 34px;
    border: 1px solid var(--sand-deep);
    border-radius: var(--radius-sm);
    background: rgba(255, 252, 245, 0.9);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 0.92rem;
    font-weight: 500;
    text-align: right;
    transition: all 0.25s var(--ease-out);
    -moz-appearance: textfield;
    appearance: textfield;
    min-height: 44px;
}

.input-wrap input[type="number"]::-webkit-inner-spin-button,
.input-wrap input[type="number"]::-webkit-outer-spin-button {
    opacity: 1;
    cursor: pointer;
}

.input-wrap input[type="number"]:focus {
    outline: none;
    border-color: var(--terracotta);
    background: white;
    box-shadow: 0 0 0 3px rgba(193, 97, 58, 0.12);
}

.input-unit {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--sand-dark);
    pointer-events: none;
    padding-right: 6px;
    line-height: 1;
}

/* --- Multi Input --- */
.multi-input {
    align-items: flex-start;
    gap: 10px;
}

.multi-inputs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.multi-inputs .input-wrap input[type="number"] {
    width: 72px;
    padding-right: 8px;
    text-align: center;
}

/* --- Buttons --- */
.buttons {
    display: flex;
    gap: 10px;
}

button {
    font-family: var(--font-ui);
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.25s var(--ease);
}

.btn-primary {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    background: var(--terracotta);
    color: white;
    font-size: 0.92rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-terracotta);
    letter-spacing: 0.02em;
    min-height: 50px;
}

.btn-primary:hover {
    background: var(--terracotta-deep);
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(193, 97, 58, 0.35);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    flex: 0 0 auto;
    padding: 14px 18px;
    background: transparent;
    color: var(--olive);
    font-size: 0.88rem;
    border-radius: var(--radius-md);
    border: 1.5px solid var(--olive-light);
    letter-spacing: 0.02em;
    min-height: 50px;
}

.btn-secondary:hover {
    background: var(--olive-ghost);
    border-color: var(--olive);
    transform: translateY(-1px);
}

/* --- Results --- */
.results {
    background: linear-gradient(135deg, rgba(255, 252, 245, 0.9) 0%, rgba(245, 237, 216, 0.7) 100%);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 18px;
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.result-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.result-grid.three-col {
    grid-template-columns: 1fr 1fr 1fr;
}

.result-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 8px;
    background: rgba(255, 252, 245, 0.7);
    border: 1px solid var(--sand-deep);
    border-radius: var(--radius-sm);
    gap: 4px;
}

.result-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-muted);
}

.result-value {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--terracotta-deep);
}

.result-optimal {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px;
    background: linear-gradient(135deg, var(--terracotta) 0%, var(--terracotta-deep) 100%);
    border-radius: var(--radius-sm);
    gap: 2px;
}

.result-optimal-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(255,255,255,0.7);
}

.result-optimal-value {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 600;
    color: white;
    line-height: 1.1;
}

.result-optimal-value small {
    font-size: 0.9rem;
    font-weight: 400;
    opacity: 0.8;
}

.dual-sol {
    padding: 12px 14px;
    background: var(--olive-ghost);
    border: 1px solid rgba(92, 107, 58, 0.2);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--ink-soft);
    font-style: italic;
    line-height: 1.5;
}

.dual-label {
    display: block;
    font-style: normal;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--olive);
    margin-bottom: 4px;
}

.error-msg {
    font-size: 0.85rem;
    color: #C0392B;
    font-weight: 600;
    padding: 10px 12px;
    background: rgba(192, 57, 43, 0.08);
    border: 1px solid rgba(192, 57, 43, 0.2);
    border-radius: var(--radius-sm);
}

/* --- Right Panel --- */
.panel-right {
    flex: 1;
    padding: clamp(16px, 3vw, 32px);
    background: rgba(255, 252, 245, 0.4);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.plot-header {
    margin-bottom: 16px;
}

.plot-header h3 {
    font-family: var(--font-display);
    font-size: clamp(1.1rem, 3vw, 1.4rem);
    font-weight: 600;
    color: var(--terracotta-deep);
    margin-bottom: 2px;
}

.plot-hint {
    font-size: 0.8rem;
    color: var(--ink-muted);
    font-style: italic;
}

/* --- Simplex Tableaux --- */
.tableaux-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.iteration-block {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 18px;
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow-sm);
}

.iteration-block h4 {
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--terracotta-deep);
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(200, 155, 60, 0.15);
}

.simplex-table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.simplex-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    font-family: var(--font-ui);
    background: white;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.simplex-table th {
    background: linear-gradient(135deg, var(--terracotta) 0%, var(--terracotta-deep) 100%);
    color: white;
    padding: 10px 12px;
    text-align: center;
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.04em;
}

.simplex-table td {
    border: 1px solid rgba(214, 201, 168, 0.4);
    padding: 9px 12px;
    text-align: center;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.simplex-table tr:hover td {
    background-color: rgba(193, 97, 58, 0.04);
}

.pivot-row td {
    background-color: rgba(92, 107, 58, 0.08) !important;
    font-weight: 600;
    color: var(--olive-deep);
}

.pivot-info {
    margin-top: 10px;
    font-style: italic;
    font-size: 0.8rem;
    color: var(--olive);
    display: flex;
    align-items: center;
    gap: 6px;
}

.pivot-info::before {
    content: '↳';
    font-style: normal;
    color: var(--gold);
}

/* ============================================================
   RESPONSIVE — Mobile First
   ============================================================ */

/* Tablet */
@media (max-width: 900px) {
    .panel-left {
        width: 340px;
        min-width: 340px;
    }
}

/* Mobile */
@media (max-width: 680px) {
    body {
        overflow-x: hidden;
    }

    /* Header compactness */
    .header {
        padding: 20px 16px;
    }

    .header-ornament {
        width: 90px;
    }

    /* Tabs stack */
    .tabs {
        flex-direction: column;
    }

    .tab-btn {
        width: 100%;
        border-bottom: 1px solid var(--sand-deep);
        min-height: 52px;
        padding: 14px 20px;
    }

    .tab-btn.active::after {
        display: none;
    }

    .tab-btn.active {
        background: var(--terracotta);
        color: white;
    }

    .tab-btn.active .tab-num {
        color: rgba(255,255,255,0.8);
    }

    /* Content stacks vertically */
    .tab-content.active {
        flex-direction: column;
    }

    .panel-left {
        width: 100%;
        min-width: 0;
        border-right: none;
        border-bottom: 2px solid var(--sand-deep);
        padding: 16px;
    }

    .panel-right {
        width: 100%;
        padding: 16px;
        background: white;
    }

    /* Inputs full-width on mobile */
    .form-group {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        gap: 8px;
    }

    .form-group label {
        flex: 1;
        min-width: 130px;
    }

    .input-wrap input[type="number"] {
        width: 100px;
        min-height: 48px;
        font-size: 1rem;
    }

    /* Multi-input on mobile */
    .multi-input {
        flex-wrap: wrap;
    }

    .multi-inputs {
        flex: 1;
    }

    .multi-inputs .input-wrap input[type="number"] {
        width: 68px;
        min-height: 48px;
    }

    /* Result grid */
    .result-grid {
        grid-template-columns: 1fr 1fr;
    }

    .result-grid.three-col {
        grid-template-columns: 1fr 1fr 1fr;
    }

    /* Plot */
    #plot {
        min-height: 520px !important;
    }

    /* Buttons */
    .buttons {
        flex-direction: row;
    }

    .btn-primary, .btn-secondary {
        min-height: 52px;
    }

    /* Tableaux */
    .simplex-table {
        font-size: 0.78rem;
    }

    .simplex-table th,
    .simplex-table td {
        padding: 8px 8px;
    }
}

/* Very small screens */
@media (max-width: 380px) {
    .result-grid.three-col {
        grid-template-columns: 1fr 1fr;
    }

    .multi-inputs .input-wrap input[type="number"] {
        width: 58px;
    }
}

/* ============================================================
   Page Entry Animation
   ============================================================ */
.header {
    animation: slideDown 0.6s var(--ease-out) both;
}

.tabs {
    animation: slideDown 0.6s 0.1s var(--ease-out) both;
}

.panel-left {
    animation: fadeIn 0.7s 0.2s var(--ease-out) both;
}

.panel-right {
    animation: fadeIn 0.7s 0.3s var(--ease-out) both;
}

.card-glass {
    animation: fadeUp 0.5s var(--ease-out) both;
}

.card-glass:nth-child(3) { animation-delay: 0.1s; }
.card-glass:nth-child(4) { animation-delay: 0.2s; }
.card-glass:nth-child(5) { animation-delay: 0.3s; }
.card-glass:nth-child(6) { animation-delay: 0.4s; }

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}
