/* ───────────────────────────────────────
   Calendar Maker — Styles
   Editorial / Stationery aesthetic
   ─────────────────────────────────────── */

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

:root {
    --bg: #f5f3ee;
    --surface: #ffffff;
    --surface-alt: #f9f7f3;
    --border: #e4e0d8;
    --border-light: #edeae3;
    --text: #2c2825;
    --text-dim: #7a746b;
    --text-faint: #b0a99e;
    --accent: #c45d3e;
    --accent-hover: #a84d32;
    --accent-light: #fdf0ec;
    --toggle-bg: #d5d0c8;
    --toggle-active: #c45d3e;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.04);
    --shadow-lg: 0 12px 40px rgba(0,0,0,.1), 0 4px 12px rgba(0,0,0,.05);
    --shadow-paper: 0 2px 8px rgba(0,0,0,.08), 0 12px 40px rgba(0,0,0,.06);
    --radius: 10px;
    --radius-sm: 7px;
    --panel-width: 340px;
    --header-h: 64px;
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-display: 'Fraunces', Georgia, serif;
}

html {
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ─── HEADER ──────────────────────── */

.header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--accent);
}

.logo-text {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 1.25rem;
    letter-spacing: -0.01em;
    color: var(--text);
}

.tagline {
    font-size: 0.82rem;
    color: var(--text-dim);
    white-space: nowrap;
}

/* ─── MAIN LAYOUT ─────────────────── */

.main {
    display: flex;
    height: calc(100dvh - var(--header-h));
}

/* ─── PANEL ───────────────────────── */

.panel {
    width: var(--panel-width);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.panel-scroll::-webkit-scrollbar {
    width: 5px;
}

.panel-scroll::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

/* ─── CUSTOM YEAR INPUT ───────────── */

.custom-year-input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: var(--font);
    font-size: 0.88rem;
    color: var(--text);
    transition: border-color .2s, opacity .2s, max-height .25s ease;
    max-height: 44px;
    margin-top: 6px;
    -moz-appearance: textfield;
}

.custom-year-input::-webkit-inner-spin-button,
.custom-year-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.custom-year-input:focus {
    outline: none;
    border-color: var(--accent);
}

.custom-year-input.hidden {
    display: none;
}

/* ─── CONTROL GROUP ───────────────── */

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
}

.divider {
    border: none;
    height: 1px;
    background: var(--border-light);
    margin: 2px 0;
}

/* ─── SEGMENTED BUTTONS ───────────── */

.seg-group {
    display: flex;
    gap: 0;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px;
}

.seg-group.seg-wrap {
    flex-wrap: wrap;
}

.seg-btn {
    flex: 1;
    padding: 7px 10px;
    border: none;
    background: transparent;
    border-radius: 5px;
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-dim);
    cursor: pointer;
    transition: all .2s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.seg-btn:hover {
    color: var(--text);
}

.seg-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.seg-wrap .seg-btn {
    min-width: calc(33.333% - 4px);
}

.orient-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(0,0,0,.1);
}

/* ─── SELECT ──────────────────────── */

.select-wrap {
    position: relative;
}

.select-wrap select {
    width: 100%;
    padding: 9px 32px 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: var(--font);
    font-size: 0.88rem;
    color: var(--text);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    transition: border-color .2s;
}

.select-wrap select:focus {
    outline: none;
    border-color: var(--accent);
}

.select-arrow {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    color: var(--text-dim);
    pointer-events: none;
}

/* ─── TOGGLES ─────────────────────── */

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
}

.toggle-row + .toggle-row {
    border-top: 1px solid var(--border-light);
}

.toggle-label {
    font-size: 0.88rem;
    color: var(--text);
}

.toggle {
    width: 44px;
    height: 26px;
    border-radius: 13px;
    background: var(--toggle-bg);
    border: none;
    padding: 3px;
    cursor: pointer;
    transition: background .25s ease;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.toggle.active {
    background: var(--toggle-active);
}

.toggle-knob {
    display: block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
    transition: transform .25s cubic-bezier(.4, .0, .2, 1);
}

.toggle.active .toggle-knob {
    transform: translateX(18px);
}

/* ─── VERSION ROW ─────────────────── */

.version-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 4px 0 0;
}

.version-tag {
    text-align: center;
    font-size: 10px;
    color: var(--text-faint);
    letter-spacing: 0.06em;
    opacity: 0.6;
}

.btn-update {
    padding: 4px 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-faint);
    font-family: var(--font);
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    -webkit-appearance: none;
    transition: all 0.2s ease;
}

.btn-update:active {
    background: var(--surface-alt);
    color: var(--accent);
    border-color: var(--accent);
}

/* ─── BUTTONS ─────────────────────── */

.panel-footer {
    flex-shrink: 0;
    padding: 14px 20px max(14px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-light);
    background: var(--surface);
}

.actions {
    display: flex;
    gap: 8px;
}

.btn {
    flex: 1;
    padding: 11px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    transition: all .2s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.btn-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.btn-secondary {
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border-light);
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn:active {
    transform: scale(.97);
}

/* ─── PREVIEW AREA ────────────────── */

.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    gap: 16px;
    min-width: 0;
    overflow: hidden;
}

.preview-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
}

#previewCanvas {
    box-shadow: var(--shadow-paper);
    border-radius: 2px;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: box-shadow .3s;
}

/* ─── PAGE NAV ────────────────────── */

.page-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    margin-top: -8px;
}

.page-nav.hidden {
    display: none;
}

.page-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all .2s;
    -webkit-tap-highlight-color: transparent;
}

.page-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.page-btn:disabled {
    opacity: .3;
    pointer-events: none;
}

.page-btn svg {
    width: 14px;
    height: 14px;
}

.page-info {
    font-size: 0.82rem;
    color: var(--text-dim);
    min-width: 100px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* ─── RESPONSIVE ──────────────────── */

@media (max-width: 860px) {
    :root {
        --panel-width: 100%;
        --header-h: 56px;
    }

    .tagline {
        display: none;
    }

    .main {
        flex-direction: column;
        height: auto;
        min-height: calc(100dvh - var(--header-h));
    }

    .panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow: visible;
    }

    .panel-scroll {
        padding: 16px;
        gap: 14px;
        max-height: none;
        overflow: visible;
    }

    .preview-area {
        padding: 16px;
        min-height: 50vh;
    }

    .panel-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 12px 16px max(12px, env(safe-area-inset-bottom));
        z-index: 100;
        border-top: 1px solid var(--border);
        box-shadow: 0 -2px 8px rgba(0,0,0,.06);
    }

    .preview-area {
        padding-bottom: 120px;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 14px;
    }

    .seg-wrap .seg-btn {
        min-width: calc(33.333% - 4px);
        padding: 7px 6px;
        font-size: 0.78rem;
    }

    .header-inner {
        padding: 0 16px;
    }
}

/* ─── PRINT ───────────────────────── */

@media print {
    .header, .panel, .page-nav { display: none !important; }
    .preview-area { padding: 0; }
    body { background: white; }
}

/* ─── LOADING STATE ───────────────── */

.btn.loading {
    pointer-events: none;
    opacity: .7;
}

.btn.loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    margin-left: 4px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
