/* ─────────────────────────────────────────────────────────────
   Minimal Date — replaces the browser's built-in date picker with a
   calendar that matches the rest of the UI.

   Same contract as minimal-select: the original <input type="date">
   stays in the DOM as the value holder, so code reading/writing
   `.value` (YYYY-MM-DD) and listening for `change` is unaffected.
   ───────────────────────────────────────────────────────────── */

.md-wrap {
    display: contents;
}

.md-native {
    display: none !important;
}

/* ── Trigger ───────────────────────────────────────────────── */

/* Zero-specificity defaults so an inherited .date-input rule still wins */
button:where(.md-trigger) {
    padding: 0 calc(8px * var(--ui-scale, 1));
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: calc(6px * var(--ui-scale, 1));
    background: var(--surface-color, #ffffff);
    color: var(--text-primary, #333333);
    font-size: calc(12px * var(--ui-scale, 1));
}

.md-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: calc(6px * var(--ui-scale, 1));
    min-width: 0;
    font-family: inherit;
    line-height: 1.2;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.md-trigger:focus-visible,
.md-wrap.open .md-trigger {
    outline: none;
    border-color: var(--primary-color, #2196f3);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.12);
}

.md-trigger:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.md-trigger-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.md-trigger-text.placeholder {
    color: var(--text-muted, #999999);
}

.md-trigger-icon {
    flex-shrink: 0;
    width: calc(12px * var(--ui-scale, 1));
    height: calc(12px * var(--ui-scale, 1));
    color: var(--text-muted, #999999);
}

.md-wrap.open .md-trigger-icon {
    color: var(--primary-color, #2196f3);
}

/* ── Panel ─────────────────────────────────────────────────── */

.md-panel {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000001;
    width: calc(252px * var(--ui-scale, 1));
    padding: calc(10px * var(--ui-scale, 1));
    background: var(--surface-color, #ffffff);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: calc(8px * var(--ui-scale, 1));
    box-shadow: 0 10px 28px rgba(15, 25, 35, 0.14), 0 2px 6px rgba(15, 25, 35, 0.07);

    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(calc(-4px * var(--ui-scale, 1)));
    transition: opacity 0.14s ease, transform 0.14s ease, visibility 0s linear 0.14s;
}

.md-panel.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
    transition: opacity 0.14s ease, transform 0.14s ease, visibility 0s;
}

/* ── Header ────────────────────────────────────────────────── */

.md-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: calc(4px * var(--ui-scale, 1));
    margin-bottom: calc(8px * var(--ui-scale, 1));
}

.md-title {
    flex: 1;
    padding: calc(4px * var(--ui-scale, 1)) calc(6px * var(--ui-scale, 1));
    border: none;
    background: transparent;
    border-radius: calc(6px * var(--ui-scale, 1));
    font-family: inherit;
    font-size: calc(12.5px * var(--ui-scale, 1));
    font-weight: 600;
    color: var(--text-primary, #333333);
    text-align: left;
    cursor: pointer;
}

.md-title:hover {
    background: var(--surface-hover, #f0f2f5);
}

.md-nav {
    width: calc(24px * var(--ui-scale, 1));
    height: calc(24px * var(--ui-scale, 1));
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background: transparent;
    border-radius: calc(6px * var(--ui-scale, 1));
    color: var(--text-secondary, #666666);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.md-nav:hover {
    background: var(--surface-hover, #f0f2f5);
    color: var(--primary-color, #2196f3);
}

.md-nav svg {
    width: calc(11px * var(--ui-scale, 1));
    height: calc(11px * var(--ui-scale, 1));
}

/* ── Grid ──────────────────────────────────────────────────── */

.md-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: calc(2px * var(--ui-scale, 1));
}

.md-dow {
    padding: calc(4px * var(--ui-scale, 1)) 0;
    font-size: calc(9.5px * var(--ui-scale, 1));
    font-weight: 600;
    color: var(--text-muted, #999999);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.md-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid transparent;
    background: transparent;
    border-radius: calc(6px * var(--ui-scale, 1));
    font-family: inherit;
    font-size: calc(11.5px * var(--ui-scale, 1));
    color: var(--text-primary, #333333);
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.md-day:hover:not(:disabled) {
    background: var(--surface-hover, #f0f2f5);
}

/* Days spilling in from the neighbouring months stay readable but recede */
.md-day.outside {
    color: var(--text-muted, #999999);
    opacity: 0.65;
}

.md-day.today {
    border-color: var(--primary-color, #2196f3);
    font-weight: 600;
}

.md-day.selected,
.md-day.selected:hover {
    background: var(--primary-color, #2196f3);
    border-color: var(--primary-color, #2196f3);
    color: #ffffff;
    font-weight: 600;
}

.md-day:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.45);
}

.md-day:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ── Month / year pickers ──────────────────────────────────── */

.md-months {
    display: none;
    grid-template-columns: repeat(3, 1fr);
    gap: calc(4px * var(--ui-scale, 1));
}

.md-panel.picking .md-months {
    display: grid;
}

.md-panel.picking .md-grid {
    display: none;
}

.md-month {
    padding: calc(8px * var(--ui-scale, 1)) 0;
    border: 1px solid transparent;
    background: transparent;
    border-radius: calc(6px * var(--ui-scale, 1));
    font-family: inherit;
    font-size: calc(11.5px * var(--ui-scale, 1));
    color: var(--text-primary, #333333);
    cursor: pointer;
    transition: background 0.12s ease;
}

.md-month:hover {
    background: var(--surface-hover, #f0f2f5);
}

.md-month.selected {
    background: var(--primary-color, #2196f3);
    color: #ffffff;
    font-weight: 600;
}

/* ── Footer ────────────────────────────────────────────────── */

.md-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: calc(8px * var(--ui-scale, 1));
    margin-top: calc(8px * var(--ui-scale, 1));
    padding-top: calc(8px * var(--ui-scale, 1));
    border-top: 1px solid var(--border-color, #e0e0e0);
}

.md-foot button {
    padding: calc(4px * var(--ui-scale, 1)) calc(8px * var(--ui-scale, 1));
    border: none;
    background: transparent;
    border-radius: calc(6px * var(--ui-scale, 1));
    font-family: inherit;
    font-size: calc(11.5px * var(--ui-scale, 1));
    font-weight: 500;
    color: var(--primary-color, #2196f3);
    cursor: pointer;
    transition: background 0.12s ease;
}

.md-foot button:hover {
    background: var(--surface-hover, #f0f2f5);
}

.md-foot .md-clear {
    color: var(--text-secondary, #666666);
}

/* ── Dark theme ────────────────────────────────────────────── */

body.theme-dark .md-panel {
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
}

body.theme-dark .md-day.selected,
body.theme-dark .md-month.selected {
    background: #1d84d6;
    border-color: #1d84d6;
}

/* ── Reduced motion ────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .md-trigger,
    .md-panel,
    .md-day,
    .md-nav,
    .md-month {
        transition: none;
    }
}
