/* ========================================
   FreeWhen - Stylesheet
   ======================================== */

:root {
    --bg: #F0FDF4;
    --bg-body: #F7FDF9;
    --bg-card: #FFFFFF;
    --ink: #1A2332;
    --ink-soft: #4A5568;
    --muted: #94A3B8;
    --border: #E2E8F0;
    --accent: #10B981;
    --accent-hover: #059669;
    --accent-light: #D1FAE5;
    --accent-glow: rgba(16, 185, 129, 0.15);
    --accent-faint: #ECFDF5;
    --danger: #EF4444;
    --warning: #F59E0B;
    --warning-light: #FEF3C7;
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 20px rgba(0,0,0,0.06);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --pad: clamp(1rem, 4vw, 1.5rem);
    --max-w: 560px;
    --transition: 0.2s ease;
}

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

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

body {
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100dvh;
}

/* ---- Layout ---- */

.container {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: var(--pad);
}

.page-center {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-center .container {
    width: 100%;
}

.event-container {
    padding-top: 1rem;
    padding-bottom: 3rem;
}

/* ---- Hero ---- */

.hero {
    text-align: center;
    margin-bottom: 2rem;
}

.logo {
    width: clamp(160px, 40vw, 200px);
    height: auto;
    margin-bottom: 0.75rem;
}

.tagline {
    color: var(--ink-soft);
    font-size: 1.1rem;
    font-weight: 400;
}

/* ---- Cards ---- */

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: clamp(1.25rem, 4vw, 1.75rem);
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
    animation: fadeUp 0.35s ease both;
}

.card-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--ink);
}

.card-subtitle {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--ink);
}

/* ---- Forms ---- */

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ink-soft);
    margin-bottom: 0.375rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.input {
    width: 100%;
    padding: 0.7rem 0.875rem;
    font-size: 1rem;
    font-family: var(--sans);
    color: var(--ink);
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input::placeholder {
    color: var(--muted);
}

input[type="date"] {
    cursor: pointer;
}

.form-error {
    color: var(--danger);
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: #FEF2F2;
    border-radius: var(--radius-xs);
}

/* ---- Buttons ---- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--sans);
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

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

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-outline {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
}

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

.btn-ghost {
    background: transparent;
    color: var(--accent);
    border-color: transparent;
}

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

.btn-full {
    width: 100%;
}

/* ---- Share Box ---- */

.share-success {
    text-align: center;
    margin-bottom: 1.25rem;
}

.share-icon {
    width: 48px;
    height: 48px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.share-event-name {
    color: var(--ink-soft);
    font-size: 0.95rem;
}

.share-box {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.share-url-input {
    flex: 1;
    font-size: 0.875rem;
    background: var(--accent-faint);
    border-color: var(--accent-light);
    color: var(--accent-hover);
    font-weight: 500;
}

.share-box .btn {
    flex-shrink: 0;
    white-space: nowrap;
}

/* ---- Back Link ---- */

.back-link {
    display: inline-block;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 1rem;
    transition: color var(--transition);
}

.back-link:hover {
    color: var(--accent);
}

/* ---- Event Header ---- */

.event-header {
    margin-bottom: 1.25rem;
}

.event-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.3;
    margin-bottom: 0.25rem;
}

.event-dates {
    color: var(--ink-soft);
    font-size: 0.95rem;
}

/* ---- Calendar ---- */

.date-instruction {
    font-size: 0.9rem;
    color: var(--ink-soft);
    margin-bottom: 0.75rem;
}

.cal-month {
    margin-bottom: 1rem;
}

.cal-month:last-child {
    margin-bottom: 1.25rem;
}

.cal-month-header {
    font-weight: 600;
    font-size: 0.95rem;
    text-align: center;
    margin-bottom: 0.5rem;
    color: var(--ink);
}

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

.cal-dow {
    text-align: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--muted);
    padding: 0.25rem 0;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.cal-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-xs);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.15s ease;
    position: relative;
    color: var(--ink);
}

.cal-cell:hover {
    background: var(--accent-light);
}

.cal-cell:active {
    transform: scale(0.92);
}

.cal-cell.selected {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.cal-cell.selected:hover {
    background: var(--accent-hover);
}

.cal-cell.selected::after {
    content: '\2713';
    position: absolute;
    top: 2px;
    right: 3px;
    font-size: 0.55rem;
    font-weight: 700;
    color: rgba(255,255,255,0.7);
}

.cal-cell.disabled {
    color: var(--border);
    cursor: default;
    pointer-events: none;
}

.cal-cell.empty {
    pointer-events: none;
}

/* ---- Edit Notice ---- */

.edit-notice {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    background: var(--accent-faint);
    border: 1px solid var(--accent-light);
    border-radius: var(--radius-xs);
    margin-bottom: 1rem;
    font-size: 0.85rem;
    color: var(--accent-hover);
}

.edit-notice strong {
    font-weight: 600;
}

.edit-notice-cancel {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0 0.25rem;
    line-height: 1;
    transition: color var(--transition);
}

.edit-notice-cancel:hover {
    color: var(--ink);
}

/* ---- Results ---- */

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.results-header .card-title {
    margin-bottom: 0;
}

.respondent-count {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-light);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
}

.result-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    animation: fadeUp 0.3s ease both;
}

.result-item:last-child {
    border-bottom: none;
}

.result-date-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.result-date {
    font-weight: 600;
    font-size: 0.95rem;
}

.result-count {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
}

.result-count.perfect {
    background: var(--accent-light);
    color: var(--accent-hover);
}

.result-count.partial {
    background: var(--warning-light);
    color: #92400E;
}

.result-count.low {
    background: #FEF2F2;
    color: #991B1B;
}

.result-bar-track {
    height: 8px;
    background: #F1F5F9;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.4rem;
}

.result-bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.5s ease;
}

.result-bar-fill.perfect {
    background: var(--accent);
}

.result-bar-fill.partial {
    background: var(--warning);
}

.result-bar-fill.low {
    background: var(--danger);
}

.result-names {
    font-size: 0.8rem;
    color: var(--muted);
}

.result-missing {
    color: var(--danger);
    font-weight: 500;
}

/* ---- Insight Box ---- */

.insight-box {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.insight-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
    line-height: 1.4;
}

.insight-box p {
    font-size: 0.9rem;
    color: var(--ink-soft);
    line-height: 1.5;
}

.insight-box strong {
    color: var(--ink);
}

/* ---- People List ---- */

.person-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.5rem;
    margin: 0 -0.5rem;
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: background var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.person-item:last-child {
    border-bottom: none;
}

.person-item:hover {
    background: var(--accent-faint);
}

.person-name {
    font-weight: 500;
    font-size: 0.95rem;
}

.person-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.person-dates-count {
    font-size: 0.8rem;
    color: var(--muted);
}

.person-edit {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.person-item.no-edit {
    cursor: default;
}

.person-item.no-edit:hover {
    background: transparent;
}

/* ---- Action Buttons ---- */

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* ---- Empty State ---- */

.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--muted);
}

.empty-state p {
    font-size: 0.95rem;
    margin-bottom: 1rem;
}

/* ---- Error / 404 ---- */

.error-card {
    text-align: center;
    padding: 2.5rem 1.5rem;
}

.error-icon {
    width: 56px;
    height: 56px;
    background: var(--warning-light);
    color: var(--warning);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.error-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.error-message {
    color: var(--ink-soft);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

/* ---- Toast ---- */

.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--ink);
    color: #fff;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    z-index: 1000;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ---- Loading Spinner ---- */

.btn .spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.btn.loading .spinner {
    display: block;
}

.btn.loading span {
    display: none;
}

/* ---- Utilities ---- */

.hidden {
    display: none !important;
}

/* ---- Animations ---- */

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

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

/* ---- Responsive ---- */

@media (min-width: 420px) {
    .cal-cell {
        font-size: 0.95rem;
    }
}

@media (min-width: 640px) {
    :root {
        --max-w: 600px;
    }
}
