/* ===== Cycle Tracker v4 — style.css ===== */

.ci-wrap {
    --ci-font:        'Segoe UI', system-ui, -apple-system, sans-serif;
    --ci-bg:          #faf8fb;
    --ci-surface:     #ffffff;
    --ci-surface2:    #f3eef7;
    --ci-border:      #e4d9ef;
    --ci-text:        #1e1328;
    --ci-text-muted:  #7b6b91;
    --ci-accent:      #9b5de5;
    --ci-accent-soft: #ede3f9;

    font-family: var(--ci-font);
    background: var(--ci-bg);
    color: var(--ci-text);
    border-radius: 14px;
    padding: 14px;
    max-width: 900px;
    margin: 0 auto;
    box-sizing: border-box;
    transition: background 0.3s, color 0.3s;
}

.ci-wrap.ci-dark {
    --ci-bg:          #120d1e;
    --ci-surface:     #1d1530;
    --ci-surface2:    #271d3e;
    --ci-border:      #3a2d56;
    --ci-text:        #f0eaf9;
    --ci-text-muted:  #9e8fba;
    --ci-accent:      #c77dff;
    --ci-accent-soft: #2a1d44;
}

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

/* ---- Header ---- */
.ci-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; }
.ci-title-group { display:flex; align-items:center; gap:7px; }
.ci-icon { font-size:1.3rem; color:var(--ci-accent); }
.ci-title { font-size:1.1rem; font-weight:700; letter-spacing:-0.02em; }

.ci-theme-toggle {
    background: var(--ci-surface2);
    border: 1.5px solid var(--ci-border);
    border-radius: 50%;
    width: 36px; height: 36px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s, transform 0.15s, border-color 0.2s;
    flex-shrink: 0; color: var(--ci-text);
}
.ci-theme-toggle:hover { transform:scale(1.1); background:var(--ci-accent-soft); border-color:var(--ci-accent); }
.ci-toggle-icon { display:flex; align-items:center; justify-content:center; }
.ci-light .ci-icon-sun  { display:none; }
.ci-light .ci-icon-moon { display:block; color:#5a3e8a; }
.ci-dark  .ci-icon-moon { display:none; }
.ci-dark  .ci-icon-sun  { display:block; color:#ffd966; }

/* ---- Controls ---- */
/* Mobile portrait: date full width on row 1, cycle+period compact on row 2 */
.ci-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
        "date  date"
        "cycle period";
    gap: 8px;
    margin-bottom: 12px;
}
.ci-control-date   { grid-area: date; }
.ci-control-cycle  { grid-area: cycle; }
.ci-control-period { grid-area: period; }

.ci-label { font-size:0.65rem; font-weight:700; text-transform:uppercase; letter-spacing:0.07em; color:var(--ci-text-muted); margin-bottom:3px; display:block; }

.ci-input {
    background: var(--ci-surface);
    border: 1.5px solid var(--ci-border);
    border-radius: 8px;
    color: var(--ci-text);
    font-size: 0.85rem;
    padding: 7px 9px;
    width: 100%;
    transition: border-color 0.2s;
    font-family: var(--ci-font);
}
.ci-input:focus { outline:none; border-color:var(--ci-accent); }
.ci-input-readonly { cursor:pointer; user-select:none; }
.ci-input-readonly:hover { border-color:var(--ci-accent); }

/* ---- Slider Popover ---- */
.ci-slider-popover { position:relative; }

.ci-popover-panel {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 200px;
    background: var(--ci-surface);
    border: 1.5px solid var(--ci-accent);
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: 0 6px 24px rgba(100,60,160,0.18);
    z-index: 200;
}
/* Right-side popovers: align right so they don't overflow */
.ci-control-period .ci-popover-panel { left:auto; right:0; }

.ci-slider-popover.ci-pop-open .ci-popover-panel { display:block; }

.ci-popover-header { display:flex; align-items:baseline; gap:4px; margin-bottom:10px; }
.ci-popover-label { font-size:0.72rem; font-weight:700; color:var(--ci-text-muted); flex:1; }
.ci-popover-val { font-size:1.25rem; font-weight:800; color:var(--ci-accent); line-height:1; }
.ci-popover-unit { font-size:0.72rem; color:var(--ci-text-muted); }

.ci-slider {
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 6px;
    background: var(--ci-border);
    border-radius: 3px; outline: none; cursor: pointer; margin-bottom: 5px;
}
.ci-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--ci-accent); border: 2px solid #fff;
    box-shadow: 0 1px 6px rgba(100,60,160,0.3); cursor: pointer;
}
.ci-slider::-moz-range-thumb {
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--ci-accent); border: 2px solid #fff; cursor: pointer;
}
.ci-slider-ticks { display:flex; justify-content:space-between; font-size:0.62rem; color:var(--ci-text-muted); }

/* ---- Legend ---- */
.ci-legend { display:flex; flex-wrap:wrap; gap:6px 12px; margin-bottom:10px; align-items:center; }
.ci-legend-item, .ci-legend-period {
    display:flex; align-items:center; gap:5px;
    font-size:0.75rem; font-weight:500; color:var(--ci-text-muted);
    cursor:pointer; user-select:none; transition:color 0.2s;
}
.ci-legend-period { cursor:default; }
.ci-legend-item.ci-hidden { opacity:0.32; }
.ci-legend-item:hover { color:var(--ci-text); }
.ci-dot { width:9px; height:9px; border-radius:50%; flex-shrink:0; }
.ci-dot-period { background:#f9645a; border-radius:3px; }

/* ---- Chart ---- */
.ci-chart-wrap {
    position:relative; background:var(--ci-surface);
    border:1px solid var(--ci-border); border-radius:12px;
    padding:10px 6px 6px; box-shadow:0 2px 16px rgba(100,60,160,0.08);
    margin-bottom:10px;
}
#ci-chart { display:block; width:100%!important; cursor:crosshair; }
.ci-phase-labels { display:flex; justify-content:space-around; padding:5px 6px 0; }
.ci-phase-label { font-size:0.58rem; text-transform:uppercase; letter-spacing:0.07em; color:var(--ci-text-muted); font-weight:700; text-align:center; }

/* ---- Hint ---- */
.ci-tap-hint { text-align:center; font-size:0.72rem; color:var(--ci-text-muted); margin-bottom:12px; }

/* ---- State Panel ---- */
.ci-state-panel {
    background:var(--ci-surface); border:1px solid var(--ci-border);
    border-radius:12px; padding:14px; margin-bottom:10px;
    box-shadow:0 2px 14px rgba(100,60,160,0.08);
}
.ci-state-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; }
.ci-state-title { font-size:0.78rem; font-weight:700; color:var(--ci-accent); text-transform:uppercase; letter-spacing:0.06em; }
.ci-state-day { font-size:0.72rem; color:var(--ci-text-muted); }
.ci-state-ranks { display:flex; flex-direction:column; gap:9px; }
.ci-rank-row { display:flex; align-items:center; gap:9px; }
.ci-rank-num {
    width:24px; height:24px; border-radius:50%;
    background:var(--ci-accent-soft); color:var(--ci-accent);
    font-size:0.68rem; font-weight:800;
    display:flex; align-items:center; justify-content:center; flex-shrink:0;
}
.ci-rank-1 .ci-rank-num { background:#fff0b3; color:#996600; }
.ci-rank-2 .ci-rank-num { background:#e8e8e8; color:#444; }
.ci-rank-3 .ci-rank-num { background:#fde0cc; color:#7a3a00; }
.ci-dark .ci-rank-1 .ci-rank-num { background:#3d3000; color:#ffd966; }
.ci-dark .ci-rank-2 .ci-rank-num { background:#2a2a3a; color:#aaa; }
.ci-dark .ci-rank-3 .ci-rank-num { background:#3d1e00; color:#ffaa66; }
.ci-rank-info { flex:1; }
.ci-rank-name { font-size:0.78rem; font-weight:700; margin-bottom:3px; }
.ci-rank-bar-wrap { height:4px; background:var(--ci-border); border-radius:2px; overflow:hidden; }
.ci-rank-bar { height:100%; border-radius:2px; transition:width 0.3s ease; }
.ci-rank-badge-wrap { display:flex; align-items:center; }

/* ---- Breakdown ---- */
.ci-breakdown {
    background:var(--ci-surface); border:1px solid var(--ci-border);
    border-radius:12px; padding:12px; box-shadow:0 2px 14px rgba(100,60,160,0.08);
    margin-bottom:10px;
}
.ci-breakdown-header {
    display:flex; align-items:baseline; gap:8px; flex-wrap:wrap;
    margin-bottom:12px; padding-bottom:8px; border-bottom:1px solid var(--ci-border);
}
.ci-breakdown-day { font-size:1rem; font-weight:700; }
.ci-breakdown-date { font-size:0.78rem; color:var(--ci-text-muted); }
.ci-breakdown-phase {
    margin-left:auto; font-size:0.66rem; font-weight:700; text-transform:uppercase;
    letter-spacing:0.06em; background:var(--ci-accent-soft); color:var(--ci-accent);
    padding:2px 9px; border-radius:20px;
}
.ci-breakdown-grid { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
.ci-metric-card { background:var(--ci-surface2); border-radius:7px; padding:10px; display:flex; flex-direction:column; gap:5px; }
.ci-metric-name { font-size:0.65rem; text-transform:uppercase; letter-spacing:0.07em; font-weight:700; color:var(--ci-text-muted); }
.ci-metric-bar-wrap { height:5px; background:var(--ci-border); border-radius:2px; overflow:hidden; }
.ci-metric-bar { height:100%; border-radius:2px; transition:width 0.3s ease; }
.ci-metric-badge { display:inline-block; font-size:0.65rem; font-weight:700; padding:2px 7px; border-radius:20px; }
.ci-metric-value { font-size:0.75rem; font-weight:600; }

/* Badges */
.ci-badge-very-low  { background:#dce8ff; color:#2c5fca; }
.ci-badge-low       { background:#d9f5eb; color:#1e7e5a; }
.ci-badge-normal    { background:#e8e8e8; color:#4a4a5a; }
.ci-badge-high      { background:#fff2d4; color:#9a5c00; }
.ci-badge-very-high { background:#fde2e0; color:#b92a20; }
.ci-dark .ci-badge-very-low  { background:#1a2f5a; color:#7aafff; }
.ci-dark .ci-badge-low       { background:#0f3322; color:#5ddba8; }
.ci-dark .ci-badge-normal    { background:#2a2a3a; color:#b0b0c8; }
.ci-dark .ci-badge-high      { background:#3d2c00; color:#ffc35a; }
.ci-dark .ci-badge-very-high { background:#3d0f0d; color:#ff8a82; }

/* ---- Guidance ---- */
.ci-guidance-wrap { display:grid; grid-template-columns:1fr; gap:10px; margin-bottom:12px; }
.ci-guidance-block {
    border-radius:12px; padding:16px;
    background:var(--ci-surface); border:1px solid var(--ci-border);
    box-shadow:0 2px 14px rgba(100,60,160,0.08);
}
.ci-guidance-you     { border-top:3px solid #c77dff; }
.ci-guidance-partner { border-top:3px solid #4cc9a0; }
.ci-guidance-icon { font-size:1.3rem; margin-bottom:5px; }
.ci-guidance-label { font-size:0.68rem; font-weight:800; text-transform:uppercase; letter-spacing:0.08em; color:var(--ci-text-muted); margin-bottom:6px; }
.ci-guidance-text { font-size:0.85rem; line-height:1.6; }
.ci-guidance-text strong { color:var(--ci-accent); }

/* ---- PDF buttons ---- */
.ci-pdf-wrap { text-align:center; margin-bottom:6px; }
.ci-pdf-btns { display:flex; gap:8px; justify-content:center; flex-wrap:wrap; margin-bottom:5px; }
.ci-pdf-btn {
    background: linear-gradient(135deg, var(--ci-accent), #7b4fc9);
    color:#fff; border:none; border-radius:30px;
    padding:10px 20px; font-size:0.84rem; font-weight:700;
    cursor:pointer; display:inline-flex; align-items:center; gap:6px;
    transition:opacity 0.2s, transform 0.15s;
    box-shadow:0 3px 12px rgba(155,93,229,0.3);
    font-family:var(--ci-font);
}
.ci-pdf-btn-dl { background:linear-gradient(135deg,#4cc9a0,#2ea888); box-shadow:0 3px 12px rgba(76,201,160,0.3); }
.ci-pdf-btn:hover { opacity:0.9; transform:translateY(-1px); }
.ci-pdf-btn:active { transform:scale(0.97); }
.ci-pdf-btn:disabled { opacity:0.6; cursor:wait; }
.ci-pdf-note { font-size:0.68rem; color:var(--ci-text-muted); }

/* ============================================================
   MOBILE PORTRAIT  (default, up to ~599px)
   Controls: date full-width top row, cycle+period side by side
   ============================================================ */
/* Already handled by the default grid above */

/* ============================================================
   MOBILE LANDSCAPE  (short viewport, rotated)
   Layout:
     Row 1: header (full width)
     Row 2: controls — all 3 in one row (full width)
     Row 3: chart (full width)
     Row 4: legend (full width)
     Row 5+: panels below
   ============================================================ */
@media (orientation:landscape) and (max-height:520px) {
    .ci-wrap {
        padding: 6px 10px;
        display: grid;
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "controls"
            "chart"
            "legend"
            "hint"
            "state"
            "breakdown"
            "guidance"
            "pdf"
            "version";
        row-gap: 6px;
    }
    .ci-header     { grid-area:header;    margin-bottom:0; }
    .ci-controls   {
        grid-area: controls;
        grid-template-columns: 1.4fr 1fr 1fr;
        grid-template-areas: "date cycle period";
        margin-bottom: 0;
        gap: 6px;
    }
    .ci-chart-wrap  { grid-area:chart;  margin-bottom:0; }
    .ci-legend      {
        grid-area: legend;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px 12px;
        margin-bottom: 0;
        justify-content: center;
    }
    .ci-tap-hint    { grid-area:hint;   margin-bottom:0; }
    .ci-state-panel { grid-area:state; }
    .ci-breakdown   { grid-area:breakdown; }
    .ci-breakdown-grid { grid-template-columns:repeat(4,1fr); }
    .ci-guidance-wrap  { grid-area:guidance; grid-template-columns:1fr 1fr; }
    .ci-pdf-wrap    { grid-area:pdf; }
    .ci-version     { grid-area:version; }
}

/* ============================================================
   TABLET / DESKTOP  (≥600px portrait or large landscape)
   ============================================================ */
@media (min-width:600px) and (not ((orientation:landscape) and (max-height:520px))) {
    .ci-wrap { padding:22px; }
    /* Controls: all on one row */
    .ci-controls {
        grid-template-columns: 1.4fr 1fr 1fr;
        grid-template-areas: "date cycle period";
    }
    .ci-breakdown-grid { grid-template-columns:repeat(4,1fr); }
    .ci-guidance-wrap  { grid-template-columns:1fr 1fr; }
}

/* ---- Version stamp ---- */
.ci-version {
    text-align: center;
    font-size: 0.6rem;
    color: var(--ci-text-muted);
    opacity: 0.5;
    margin-top: 10px;
    letter-spacing: 0.05em;
}

/* ---- Dark mode: page background ---- */
/* Injected via JS when dark mode is active — targets the nearest scrollable ancestor */
body.ci-page-dark {
    background-color: #0c0918 !important;
    transition: background-color 0.3s;
}

/* ---- Locked day indicator ---- */
.ci-wrap.ci-locked .ci-chart-wrap {
    box-shadow: 0 0 0 2px var(--ci-accent), 0 2px 16px rgba(100,60,160,0.15);
}
.ci-wrap.ci-locked .ci-tap-hint {
    color: var(--ci-accent);
    font-weight: 600;
}

/* ---- Version stamp ---- */
.ci-version {
    cursor: pointer;
    transition: color 0.2s, opacity 0.2s;
    user-select: none;
}
.ci-version:hover {
    opacity: 0.8;
}
.ci-version.ci-version-active {
    color: #c8900a;
    opacity: 0.85;
    font-weight: 700;
}
.ci-dark .ci-version.ci-version-active {
    color: #ffc93c;
}
/* Title icon clickable reset */
#ci-title-icon {
    cursor: pointer;
    transition: transform 0.2s;
    display: inline-block;
}
#ci-title-icon:hover {
    transform: rotate(-30deg) scale(1.2);
}
