/* DigHomi Court - Modern UI */

:root {
    --bg: #0f1419;
    --bg-card: #1a2332;
    --bg-hover: #243044;
    --text: #e8eaed;
    --text-muted: #8b9cb3;
    --primary: #4ade80;
    --primary-dark: #22c55e;
    --danger: #f87171;
    --warning: #fbbf24;
    --border: #2d3a4f;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

/* Header */
.header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-badge {
    font-size: 0.875rem;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--bg-hover);
}

.user-badge.role-admin {
    background: rgba(74, 222, 128, 0.15);
    color: var(--primary);
}

.user-badge.role-moderator {
    background: rgba(251, 191, 36, 0.15);
    color: var(--warning);
}

/* Main */
.main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    min-height: 44px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all 0.15s;
    touch-action: manipulation;
    user-select: none;
}

.btn-primary {
    background: var(--primary);
    color: #0f1419;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}

.btn-outline:hover {
    background: rgba(74, 222, 128, 0.1);
}

.btn-danger {
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger);
    border: 1px solid transparent;
}

.btn-danger:hover {
    background: rgba(248, 113, 113, 0.25);
}

.btn-sm {
    padding: 8px 12px;
    min-height: 40px;
    font-size: 0.8125rem;
}

.btn-block {
    width: 100%;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.875rem;
}

.alert-success {
    background: rgba(74, 222, 128, 0.15);
    color: var(--primary);
    border: 1px solid rgba(74, 222, 128, 0.3);
}

.alert-error {
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger);
    border: 1px solid rgba(248, 113, 113, 0.3);
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-group input,
.form-group textarea,
.form-group select,
.court-select {
    width: 100%;
    padding: 12px 14px;
    min-height: 44px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 16px; /* prevents iOS zoom on focus */
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.input-readonly {
    background: var(--bg-hover) !important;
    cursor: default;
}

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px 32px;
    box-shadow: var(--shadow);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 12px;
}

.login-header h1 {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Calendar */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    text-align: center;
    position: relative;
    transition: border-color 0.15s, transform 0.15s;
}

.stat-card:hover {
    border-color: rgba(74, 222, 128, 0.35);
}

.stat-icon {
    display: block;
    font-size: 0.875rem;
    opacity: 0.6;
    margin-bottom: 4px;
}

.stat-card.stat-highlight {
    border-color: var(--primary);
    background: rgba(74, 222, 128, 0.08);
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text);
}

.stat-highlight .stat-value {
    color: var(--primary);
}

.stat-label {
    display: block;
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-icon {
    min-width: 44px;
    padding: 0;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.export-dropdown {
    position: relative;
}

.btn-export {
    white-space: nowrap;
}

.export-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 200px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    z-index: 50;
    overflow: hidden;
}

.export-menu a {
    display: block;
    padding: 12px 16px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.export-menu a:last-child {
    border-bottom: none;
}

.export-menu a:hover {
    background: var(--bg-hover);
}

.section-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.calendar-compact-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.calendar-compact {
    margin-bottom: 16px;
}

.count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 0.625rem;
    font-weight: 700;
    border-radius: 9px;
    background: var(--danger);
    color: #fff;
    margin-top: 2px;
    line-height: 1;
}

.day-cell.busy-mid .count-badge {
    background: var(--warning);
    color: #0f1419;
}

.day-cell.busy-high .count-badge {
    background: #ef4444;
    font-size: 0.5625rem;
    min-width: 20px;
}

.day-panel {
    margin-bottom: 16px;
}

.day-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.day-panel-header h3 {
    font-size: 1.25rem;
    margin-bottom: 4px;
}

.day-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.meta-pill {
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 600;
}

.meta-pill.booked {
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger);
}

.meta-pill.free {
    background: rgba(74, 222, 128, 0.12);
    color: var(--primary);
}

.day-panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.badge-full {
    font-size: 0.75rem;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger);
    white-space: nowrap;
}

/* Timeline */
.timeline-wrap {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.timeline-labels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
    gap: 2px;
    margin-bottom: 4px;
}

.timeline-labels span {
    font-size: 0.5625rem;
    color: var(--text-muted);
    text-align: center;
}

.timeline-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
    gap: 3px;
    height: 28px;
}

.timeline-slot {
    border-radius: 4px;
    min-width: 0;
}

.timeline-slot.free {
    background: rgba(74, 222, 128, 0.2);
    border: 1px solid rgba(74, 222, 128, 0.35);
}

.timeline-slot.occupied {
    background: rgba(248, 113, 113, 0.55);
    border: 1px solid rgba(248, 113, 113, 0.7);
}

.timeline-slot.night {
    box-shadow: inset 0 0 0 1px rgba(147, 197, 253, 0.25);
}

.timeline-slot.night.free {
    background: rgba(96, 165, 250, 0.12);
    border-color: rgba(96, 165, 250, 0.3);
}

.timeline-slot.night.occupied {
    background: rgba(248, 113, 113, 0.65);
}

/* Bookings list */
.bookings-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.search-input {
    flex: 1;
    padding: 10px 14px;
    min-height: 44px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 16px;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
}

.bookings-count {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--primary);
    min-width: 24px;
    text-align: center;
}

.bookings-scroll {
    max-height: min(420px, 50vh);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
}

.booking-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    transition: background 0.12s;
}

.booking-row:hover {
    background: var(--bg-hover);
}

.booking-row:last-child {
    border-bottom: none;
}

.booking-row-time {
    font-weight: 700;
    font-size: 0.8125rem;
    color: var(--primary);
    white-space: nowrap;
    min-width: 72px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
}

.duration-badge {
    font-size: 0.625rem;
    padding: 2px 6px;
    border-radius: 10px;
    background: rgba(74, 222, 128, 0.15);
    color: var(--primary);
    font-weight: 600;
}

.booking-row-body {
    flex: 1;
    min-width: 0;
    font-size: 0.875rem;
}

.booking-row-body strong {
    display: block;
    margin-bottom: 2px;
}

.booking-row-phone {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.8125rem;
}

.booking-row-notes {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.booking-row-action .btn {
    min-width: 40px;
    min-height: 40px;
    padding: 0;
}

.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
}

.empty-state p {
    margin-bottom: 16px;
}

/* Free slots */
.free-slots-panel {
    margin-top: 16px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.free-slots-panel summary {
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-muted);
    padding: 8px 0;
    user-select: none;
}

.slot-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 10px;
}

.slot-chip {
    padding: 8px 12px;
    min-height: 40px;
    border-radius: 8px;
    border: 1px solid rgba(74, 222, 128, 0.4);
    background: rgba(74, 222, 128, 0.08);
    color: var(--primary);
    font-size: 0.8125rem;
    cursor: pointer;
    touch-action: manipulation;
}

.slot-chip:active {
    background: rgba(74, 222, 128, 0.2);
}

.slot-select {
    width: 100%;
    padding: 12px 14px;
    min-height: 44px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 16px;
}

.calendar-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.toolbar-left h2 {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.hours-badge {
    display: inline-block;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 4px 10px;
    border-radius: 20px;
    margin-top: 4px;
}

.court-select {
    max-width: 200px;
    margin-top: 8px;
}

.month-nav {
    display: flex;
    align-items: center;
    gap: 12px;
}

.month-label {
    font-size: 1.125rem;
    font-weight: 600;
    min-width: 160px;
    text-align: center;
}

.calendar-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

@media (min-width: 900px) {
    .calendar-grid {
        grid-template-columns: 1fr 1fr;
        gap: 24px;
        margin-bottom: 24px;
    }
}

/* Month calendar */
.weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 8px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

.days-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.day-cell {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    border: 1px solid transparent;
    transition: all 0.15s;
    padding: 4px;
    min-height: 56px;
}

.day-cell:not(.empty):hover {
    background: var(--bg-hover);
}

.day-cell.empty {
    pointer-events: none;
}

.day-cell.today .day-num {
    background: var(--primary);
    color: #0f1419;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.day-cell.selected {
    background: rgba(74, 222, 128, 0.15);
    border-color: var(--primary);
}

.day-cell.has-bookings {
    background: rgba(248, 113, 113, 0.08);
}

.day-cell.has-bookings .day-num {
    color: var(--danger);
}

.day-num {
    font-size: 0.9375rem;
    font-weight: 500;
}

/* Day detail */
.day-detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.day-detail-header h3 {
    font-size: 1.25rem;
}

.day-summary {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.time-slots {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 500px;
    overflow-y: auto;
}

.time-slot {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.time-slot.available {
    background: rgba(74, 222, 128, 0.05);
    border-color: rgba(74, 222, 128, 0.2);
}

.time-slot.occupied {
    background: rgba(248, 113, 113, 0.08);
    border-color: rgba(248, 113, 113, 0.25);
}

.slot-time {
    font-weight: 600;
    font-size: 0.875rem;
    min-width: 100px;
    color: var(--text-muted);
}

.slot-info {
    flex: 1;
    font-size: 0.875rem;
}

.slot-info strong {
    color: var(--text);
}

.slot-phone, .slot-notes {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.slot-phone {
    color: var(--primary);
    text-decoration: none;
}

.slot-phone:active {
    opacity: 0.8;
}

.slot-action, .slot-book-btn {
    flex-shrink: 0;
}

/* Visibility helpers */
.desktop-only {
    display: block;
}

.mobile-only {
    display: none;
}

/* Booking cards (mobile) */
.booking-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.booking-card-item {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    background: var(--bg);
}

.booking-card-time {
    font-weight: 700;
    font-size: 0.9375rem;
    color: var(--primary);
    margin-bottom: 8px;
}

.booking-card-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
    font-size: 0.875rem;
}

.booking-card-phone {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9375rem;
}

.booking-card-notes {
    color: var(--text-muted);
    font-size: 0.8125rem;
}

/* Table */
.bookings-list {
    margin-top: 24px;
}

.bookings-list h3 {
    margin-bottom: 16px;
    font-size: 1rem;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table th {
    text-align: left;
    padding: 10px 12px;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.table tr:last-child td {
    border-bottom: none;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal[hidden] {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 440px;
    z-index: 1;
}

.modal-content h3 {
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 8px;
}

/* ===== MOBILE RESPONSIVE ===== */

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .stat-label {
        font-size: 0.625rem;
    }

    .day-panel-header {
        flex-direction: column;
    }

    .day-panel-header .btn-primary,
    .day-panel-actions {
        width: 100%;
    }

    .day-panel-actions .btn {
        flex: 1;
    }

    .toolbar-actions {
        width: 100%;
        justify-content: space-between;
    }

    .export-menu {
        left: 0;
        right: 0;
        min-width: auto;
    }

    .bookings-scroll {
        max-height: min(360px, 45vh);
    }

    .booking-row {
        padding: 10px 12px;
        gap: 10px;
    }

    .header {
        padding: 0 12px;
        padding-top: env(safe-area-inset-top, 0);
    }

    .header-inner {
        height: 56px;
        gap: 8px;
    }

    .logo {
        font-size: 1rem;
        white-space: nowrap;
    }

    .header-user {
        gap: 8px;
        flex-shrink: 0;
    }

    .user-badge {
        font-size: 0.75rem;
        padding: 4px 8px;
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .header-user .btn-ghost {
        padding: 8px 10px;
        min-height: 40px;
        font-size: 0.8125rem;
    }

    .main {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
    }

    .card {
        padding: 16px;
        border-radius: 10px;
    }

    .login-page {
        padding: 16px;
        padding-top: calc(16px + env(safe-area-inset-top, 0));
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
    }

    .login-card {
        padding: 28px 20px;
    }

    .calendar-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-bottom: 16px;
    }

    .toolbar-left h2 {
        font-size: 1.25rem;
    }

    .court-select {
        max-width: 100%;
        margin-top: 8px;
    }

    .toolbar-right {
        width: 100%;
    }

    .month-nav {
        justify-content: center;
        width: 100%;
    }

    .month-label {
        font-size: 1rem;
        min-width: auto;
        flex: 1;
    }

    .month-nav .btn-ghost {
        min-width: 44px;
        min-height: 44px;
        padding: 0;
    }

    /* Calendar cells - compact for small screens */
    .weekdays {
        font-size: 0.625rem;
        gap: 2px;
    }

    .days-grid {
        gap: 2px;
    }

    .day-cell {
        min-height: 44px;
        aspect-ratio: auto;
        padding: 2px;
        border-radius: 6px;
    }

    .day-num {
        font-size: 0.8125rem;
    }

    .day-cell.today .day-num {
        width: 26px;
        height: 26px;
        font-size: 0.8125rem;
    }

    .count-badge {
        min-width: 16px;
        height: 16px;
        font-size: 0.5625rem;
    }

    /* Modal as bottom sheet on mobile */
    .modal {
        padding: 0;
        align-items: flex-end;
    }

    .modal-content {
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        padding: 20px 16px;
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
        max-height: 90vh;
        max-height: 90dvh;
        overflow-y: auto;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

    .modal-actions .btn {
        width: 100%;
    }

    .alert {
        font-size: 0.8125rem;
        padding: 10px 12px;
    }
}

@media (max-width: 380px) {
    .logo {
        font-size: 0.9375rem;
    }

    .user-badge {
        max-width: 72px;
    }
}

/* Touch device enhancements */
@media (hover: none) and (pointer: coarse) {
    .day-cell:not(.empty):active {
        background: var(--bg-hover);
        transform: scale(0.97);
    }

    .btn:active {
        transform: scale(0.98);
    }

    .day-cell:not(.empty):hover {
        background: transparent;
    }
}
