/* ============================================================
   Bonus Campaign Cost Simulator — Editorial Fintech Theme
   ============================================================ */

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

/* === Design Tokens === */
:root {
    /* palette */
    --bg:             #f6f4f0;
    --bg-grain:       url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
    --card:           #ffffff;
    --card-hover:     #fffffe;

    --ink:            #1c1917;
    --ink-secondary:  #78716c;
    --ink-tertiary:   #a8a29e;

    --accent:         #0f766e;
    --accent-soft:    #ccfbf1;
    --accent-hover:   #0d9488;

    --best:           #059669;
    --best-bg:        #ecfdf5;
    --worst:          #c2410c;
    --worst-bg:       #fff7ed;

    --border:         #e7e5e4;
    --border-strong:  #d6d3d1;
    --input-bg:       #fafaf9;
    --input-focus:    #0f766e;

    /* shadows */
    --shadow-sm:      0 1px 2px rgba(28,25,23,0.04);
    --shadow:         0 1px 3px rgba(28,25,23,0.06), 0 4px 12px rgba(28,25,23,0.04);
    --shadow-lg:      0 4px 24px rgba(28,25,23,0.08), 0 1px 4px rgba(28,25,23,0.04);

    /* radii */
    --radius:         10px;
    --radius-sm:      6px;

    /* type */
    --font-serif:     'Source Serif 4', Georgia, 'Times New Roman', serif;
    --font-sans:      'Outfit', system-ui, -apple-system, sans-serif;
    --font-mono:      'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
}

/* === Base === */
body {
    font-family: var(--font-sans);
    background: var(--bg);
    background-image: var(--bg-grain);
    background-size: 256px;
    color: var(--ink);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* === Header === */
header {
    position: relative;
    background: var(--ink);
    overflow: hidden;
    padding: 40px 32px 36px;
}

.header-inner {
    max-width: 1140px;
    margin: 0 auto;
    display: flex;
    align-items: flex-start;
    gap: 20px;
    position: relative;
    z-index: 1;
}

.header-badge {
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    background: var(--accent);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.85rem;
    color: white;
    letter-spacing: 1px;
    margin-top: 2px;
}

header h1 {
    font-family: var(--font-serif);
    font-size: 1.85rem;
    font-weight: 700;
    color: white;
    line-height: 1.2;
    letter-spacing: -0.3px;
}

.subtitle {
    color: var(--ink-tertiary);
    font-size: 0.9rem;
    font-weight: 400;
    margin-top: 6px;
}

.header-decoration {
    position: absolute;
    top: -30%;
    right: -5%;
    width: 380px;
    height: 380px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.04);
    pointer-events: none;
}

.header-decoration::before {
    content: '';
    position: absolute;
    top: 20%;
    left: 20%;
    width: 60%;
    height: 60%;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.06);
}

/* === Main === */
main {
    max-width: 1140px;
    margin: 0 auto;
    padding: 32px 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* === Cards === */
.card {
    position: relative;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px 28px 24px;
    border: 1px solid var(--border);
    overflow: hidden;
    transition: box-shadow 0.3s ease;
}

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

.card-accent {
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--accent);
    border-radius: 4px 0 0 4px;
}

.accent-result { background: linear-gradient(180deg, var(--best), var(--worst)); }
.accent-step   { background: #6366f1; }
.accent-scenario { background: #d97706; }
.accent-compare  { background: linear-gradient(180deg, #6366f1, #d97706); }

/* === Section Titles === */
.section-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.section-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--accent);
    color: white;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    flex-shrink: 0;
}

.card h2 {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--ink);
    margin: 0;
    letter-spacing: -0.2px;
}

.card h3 {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--ink-secondary);
    margin: 20px 0 10px;
}

.hint {
    color: var(--ink-secondary);
    font-size: 0.85rem;
    margin: -8px 0 16px;
    line-height: 1.5;
}

/* === Section Header === */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.section-header .section-title {
    margin-bottom: 0;
}

.day-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.day-controls label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ink-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* === Day Tabs === */
.day-tabs {
    display: flex;
    gap: 2px;
    margin: 16px 0;
    background: var(--input-bg);
    border-radius: var(--radius-sm);
    padding: 3px;
    border: 1px solid var(--border);
}

.day-tab {
    flex: 1;
    padding: 8px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ink-secondary);
    border-radius: 4px;
    transition: all 0.2s ease;
}

.day-tab:hover {
    color: var(--ink);
    background: rgba(255,255,255,0.6);
}

.day-tab.active {
    color: var(--accent);
    background: white;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* === Day Panel === */
.day-panel { display: none; }
.day-panel.active {
    display: block;
    animation: fadeUp 0.25s ease;
}

.day-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}

/* === Form Fields === */
.config-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 8px;
}

.config-field,
.field-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.config-field label,
.field-group label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--ink-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

/* === Inputs === */
input[type="number"],
input[type="text"],
select {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    font-weight: 500;
    background: var(--input-bg);
    color: var(--ink);
    transition: all 0.2s ease;
    width: 100%;
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
    outline: none;
    border-color: var(--input-focus);
    background: white;
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.08);
}

input[type="number"]:hover,
select:hover {
    border-color: var(--border-strong);
}

select {
    font-family: var(--font-sans);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2378716c' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

input.small-input {
    width: 80px;
}

/* === Active Day Banner === */
.active-day-banner {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 10px 16px;
    background: var(--accent-soft);
    border: 1px solid rgba(15, 118, 110, 0.15);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.82rem;
    color: var(--accent);
    flex-wrap: wrap;
}

.active-day-banner .banner-label {
    font-weight: 700;
    font-family: var(--font-sans);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.72rem;
}

.active-day-banner .banner-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 0.82rem;
}

.active-day-banner .banner-item span {
    font-family: var(--font-sans);
    font-weight: 400;
    color: var(--ink-secondary);
    font-size: 0.75rem;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-add {
    background: transparent;
    color: var(--accent);
    border: 1.5px dashed var(--border-strong);
    margin-top: 12px;
}

.btn-add:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.btn-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.btn-export {
    background: var(--ink);
    color: white;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
}

.btn-export:hover {
    background: #292524;
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-export svg {
    flex-shrink: 0;
}

.btn-danger {
    background: none;
    color: var(--ink-tertiary);
    padding: 4px 10px;
    font-size: 0.75rem;
    border-radius: 4px;
    font-weight: 500;
}

.btn-danger:hover {
    color: var(--worst);
    background: var(--worst-bg);
}

/* === Tables === */
.results-table-wrapper {
    overflow-x: auto;
    margin: 0 -4px;
    padding: 0 4px;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.84rem;
}

thead th {
    padding: 11px 14px;
    text-align: left;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--ink-tertiary);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    background: transparent;
}

thead th.col-best {
    color: var(--best);
}

thead th.col-worst {
    color: var(--worst);
}

tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-weight: 500;
    vertical-align: middle;
}

tbody td:first-child {
    font-family: var(--font-sans);
    font-weight: 600;
    color: var(--ink);
}

tbody tr {
    transition: background 0.15s ease;
}

tbody tr:hover {
    background: var(--input-bg);
}

tbody tr:last-child td {
    border-bottom: none;
}

tfoot td {
    padding: 14px 14px;
    font-weight: 700;
    border-top: 2px solid var(--ink);
    font-family: var(--font-mono);
    font-size: 0.84rem;
}

tfoot td:first-child {
    font-family: var(--font-sans);
}

td.best,
tfoot td.best {
    color: var(--best);
}

td.worst,
tfoot td.worst {
    color: var(--worst);
}

td.total-best {
    color: var(--best);
    font-weight: 700;
    background: var(--best-bg);
    border-radius: 0;
}

td.total-worst {
    color: var(--worst);
    font-weight: 700;
    background: var(--worst-bg);
    border-radius: 0;
}

tfoot td.total-best,
tfoot td.total-worst {
    font-size: 0.9rem;
}

/* === Steps Table === */
#stepsTable {
    margin-bottom: 0;
}

#stepsTable input {
    width: 110px;
}

#stepsTable td:first-child {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--ink-secondary);
    letter-spacing: 0.5px;
}

/* === Scenario Cards === */
.scenario-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 10px;
    background: var(--input-bg);
    transition: all 0.2s ease;
}

.scenario-card:hover {
    border-color: var(--border-strong);
    background: white;
}

.scenario-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.scenario-header h4 {
    font-size: 0.9rem;
    font-weight: 600;
}

.scenario-header input[type="text"] {
    border: none;
    background: none;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.92rem;
    padding: 2px 0;
    width: 160px;
    color: var(--ink);
    border-bottom: 1.5px solid transparent;
    border-radius: 0;
}

.scenario-header input[type="text"]:focus {
    border-bottom-color: var(--accent);
    box-shadow: none;
    background: none;
    outline: none;
}

.scenario-inputs {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.scenario-inputs .config-field {
    min-width: 100px;
}

.scenario-inputs input {
    width: 80px;
    text-align: center;
}

.scenario-summary {
    font-size: 0.82rem;
    color: var(--ink-secondary);
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-family: var(--font-sans);
}

.scenario-summary .total {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--ink);
}

.scenario-summary .warning {
    color: var(--worst);
    font-weight: 600;
}

/* === Scenario Results Table === */
#scenarioResultsTable td.scenario-total {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--accent);
    background: var(--accent-soft);
}

#scenarioResultsTable small {
    font-family: var(--font-sans);
    color: var(--ink-tertiary);
    font-weight: 400;
    font-size: 0.72rem;
    margin-left: 4px;
}

#scenarioResultsTable thead th small {
    display: block;
    font-weight: 500;
    color: var(--ink-tertiary);
    margin-top: 2px;
    letter-spacing: 0;
    text-transform: none;
}

/* === Download === */
.download-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.download-bar .section-title {
    margin-bottom: 0;
}

.download-buttons {
    display: flex;
    gap: 8px;
}

/* === Help Section === */
.btn-toggle {
    background: var(--input-bg);
    color: var(--ink-secondary);
    border: 1px solid var(--border);
    padding: 6px 16px;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-toggle:hover {
    border-color: var(--border-strong);
    color: var(--ink);
}

.help-content {
    display: none;
    margin-top: 20px;
}

.help-content.open {
    display: block;
    animation: fadeUp 0.3s ease;
}

.help-block {
    margin-bottom: 28px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.help-block:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.help-block h3 {
    font-family: var(--font-serif);
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    margin: 0 0 8px;
    text-transform: none;
    letter-spacing: 0;
}

.help-block p {
    font-size: 0.85rem;
    color: var(--ink-secondary);
    line-height: 1.6;
    margin-bottom: 14px;
}

.help-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 8px;
}

.help-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 14px;
    background: var(--input-bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.help-field strong {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ink);
}

.help-field span {
    font-size: 0.78rem;
    color: var(--ink-secondary);
    line-height: 1.45;
}

.help-formula {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 12px 0;
}

.formula-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 8px 14px;
    background: var(--input-bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 0.82rem;
}

.formula-row.best-row {
    background: var(--best-bg);
    border-color: rgba(5, 150, 105, 0.15);
}

.formula-row.worst-row {
    background: var(--worst-bg);
    border-color: rgba(194, 65, 12, 0.15);
}

.formula-label {
    font-family: var(--font-sans);
    font-weight: 600;
    color: var(--ink);
    min-width: 160px;
    flex-shrink: 0;
    font-size: 0.8rem;
}

.formula-eq {
    color: var(--ink-tertiary);
    font-family: var(--font-mono);
    font-weight: 600;
}

.formula-expr {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--ink-secondary);
    font-weight: 500;
}

.help-example {
    margin-top: 12px;
    padding: 14px 16px;
    background: var(--accent-soft);
    border: 1px solid rgba(15, 118, 110, 0.15);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--ink);
    line-height: 1.7;
}

.help-example strong {
    color: var(--accent);
    font-family: var(--font-mono);
    font-weight: 700;
}

/* === Footer === */
footer {
    text-align: center;
    padding: 28px 20px;
    color: var(--ink-tertiary);
    font-size: 0.8rem;
    letter-spacing: 0.3px;
}

/* === Animations === */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fade-in {
    opacity: 0;
    animation: fadeUp 0.5s ease forwards;
}

.fade-in:nth-child(1) { animation-delay: 0.05s; }
.fade-in:nth-child(2) { animation-delay: 0.1s; }
.fade-in:nth-child(3) { animation-delay: 0.15s; }
.fade-in:nth-child(4) { animation-delay: 0.2s; }
.fade-in:nth-child(5) { animation-delay: 0.25s; }
.fade-in:nth-child(6) { animation-delay: 0.3s; }

/* === Print === */
@media print {
    body { background: white; }
    header { background: var(--ink) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .day-tabs, #daily-section, #step-section, #scenario-section, #download-section, #help-section, footer { display: none !important; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
    .card-accent { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    td.total-best, td.total-worst, td.best, td.worst, tfoot td, .section-number {
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    .fade-in { opacity: 1; animation: none; }
}

/* === Responsive === */
@media (max-width: 900px) {
    .day-grid { grid-template-columns: repeat(2, 1fr); }
    .config-row { grid-template-columns: repeat(2, 1fr); }
    header { padding: 28px 20px 24px; }
    header h1 { font-size: 1.4rem; }
    main { padding: 20px 12px; }
    .card { padding: 20px; }
}

@media (max-width: 560px) {
    .day-grid { grid-template-columns: 1fr 1fr; }
    .config-row { grid-template-columns: 1fr; }
    .section-header { flex-direction: column; align-items: flex-start; }
    .scenario-inputs { flex-direction: column; }
    .download-bar { flex-direction: column; align-items: flex-start; }
    header h1 br { display: none; }
    .header-badge { width: 40px; height: 40px; font-size: 0.7rem; }
}
