/* ── CAP-TVREMOTE — Main Stylesheet ────────────────────────────────────────
   Design philosophy: calm, dark, high contrast, large targets, zero clutter
   Mobile first — designed for iPad and iPhone
   CAP Platform Standards v1.0
   ──────────────────────────────────────────────────────────────────────── */

/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
    --bg:           #0d0d1a;
    --bg-surface:   #161628;
    --bg-card:      #1e1e35;
    --bg-elevated:  #252540;

    --text-primary:   #f0f0f8;
    --text-secondary: #9898b8;
    --text-muted:     #5a5a7a;

    --accent:       #4f6ef7;
    --accent-dark:  #3a55d4;
    --success:      #2ecc71;
    --warning:      #f39c12;
    --danger:       #e74c3c;

    --border:       #2a2a45;
    --border-light: #333355;

    --radius-sm:    12px;
    --radius-md:    18px;
    --radius-lg:    24px;
    --radius-xl:    32px;

    --shadow:       0 4px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg:    0 8px 40px rgba(0, 0, 0, 0.6);

    /* Touch targets — minimum 56px for elderly users */
    --touch-min:    56px;
    --touch-lg:     72px;
    --touch-xl:     90px;

    --font:         'DM Sans', sans-serif;

    --tab-height:   64px;
    --status-height: 52px;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-primary);
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* Prevent text size adjustment on rotation */
    -webkit-text-size-adjust: 100%;
}

button {
    font-family: var(--font);
    cursor: pointer;
    border: none;
    outline: none;
    background: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

button:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* ── Status bar ─────────────────────────────────────────────────────────── */
.status-bar {
    height: var(--status-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.status-label {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.status-indicator {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.4s ease;
}

.status-indicator.connected    { background: var(--success); }
.status-indicator.disconnected { background: var(--danger); }
.status-indicator.checking     { background: var(--warning); }

/* ── Main layout ────────────────────────────────────────────────────────── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Tab nav ────────────────────────────────────────────────────────────── */
.tab-nav {
    display: flex;
    height: var(--tab-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    min-height: var(--tab-height);
    letter-spacing: 0.2px;
}

.tab-btn.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent);
}

/* ── Tab panels ─────────────────────────────────────────────────────────── */
.tab-panel {
    display: none;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-panel.active {
    display: flex;
    flex-direction: column;
}

/* ── Tile grid (Channels tab) ───────────────────────────────────────────── */
.tile-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    padding: 20px;
}

.tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 120px;
    border-radius: var(--radius-lg);
    background: var(--tile-color, var(--bg-card));
    color: #fff;
    border: none;
    box-shadow: var(--shadow);
    transition: transform 0.1s ease, opacity 0.1s ease;
    padding: 16px 12px;
    position: relative;
    overflow: hidden;
}

/* Subtle shine overlay */
.tile::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.12) 0%, transparent 60%);
    border-radius: inherit;
    pointer-events: none;
}

.tile:active {
    transform: scale(0.95);
    opacity: 0.85;
}

.tile-icon {
    font-size: 36px;
    line-height: 1;
    /* No motion — elderly friendly */
}

.tile-label {
    font-size: 16px;
    font-weight: 700;
    text-align: center;
    line-height: 1.2;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* iPad — 3 columns */
@media (min-width: 600px) {
    .tile-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 18px;
        padding: 28px;
    }

    .tile {
        min-height: 140px;
    }

    .tile-icon {
        font-size: 44px;
    }

    .tile-label {
        font-size: 18px;
    }
}

/* ── Remote tab ─────────────────────────────────────────────────────────── */
.remote-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 24px 20px;
    flex: 1;
}

/* Side controls row */
.side-controls {
    display: flex;
    gap: 16px;
    width: 100%;
    max-width: 400px;
}

.side-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ctrl-btn {
    min-height: var(--touch-min);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 700;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: transform 0.1s, background 0.1s;
    letter-spacing: 0.5px;
}

.ctrl-btn:active {
    transform: scale(0.94);
    background: var(--bg-elevated);
}

.mute-btn  { color: var(--warning); }
.back-btn  { background: var(--bg-elevated); }

/* D-pad */
.dpad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
    max-width: 280px;
}

.dpad-middle {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.dpad-btn {
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 22px;
    font-weight: 700;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: transform 0.1s, background 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.dpad-btn:active {
    transform: scale(0.92);
    background: var(--bg-elevated);
}

.dpad-up,
.dpad-down {
    width: 100%;
    height: var(--touch-xl);
}

.dpad-left,
.dpad-right {
    width: var(--touch-xl);
    height: var(--touch-xl);
    flex-shrink: 0;
}

.dpad-ok {
    flex: 1;
    height: var(--touch-xl);
    font-size: 20px;
    font-weight: 700;
    background: var(--accent);
    border-color: var(--accent-dark);
    color: #fff;
    letter-spacing: 1px;
}

.dpad-ok:active {
    background: var(--accent-dark);
}

/* Action row */
.action-row {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 400px;
}

.action-row .ctrl-btn {
    flex: 1;
    min-height: var(--touch-lg);
}

/* ── Search tab ─────────────────────────────────────────────────────────── */
.search-wrap {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 28px 20px;
    flex: 1;
}

.search-hint {
    font-size: 16px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.5;
}

.search-input {
    font-family: var(--font);
    font-size: 20px;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
}

.search-input:focus {
    border-color: var(--accent);
}

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

.send-btn {
    min-height: var(--touch-xl);
    border-radius: var(--radius-md);
    background: var(--accent);
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    border: none;
    box-shadow: var(--shadow);
    transition: transform 0.1s, background 0.1s;
    letter-spacing: 0.3px;
}

.send-btn:active {
    transform: scale(0.97);
    background: var(--accent-dark);
}

.clear-btn {
    min-height: var(--touch-min);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 17px;
    font-weight: 600;
    border: 1px solid var(--border);
    transition: transform 0.1s;
}

.clear-btn:active {
    transform: scale(0.97);
}

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    padding: 14px 28px;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 100;
    max-width: 90vw;
    text-align: center;
    white-space: nowrap;
}

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

.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--danger);  color: var(--danger);  }

/* ── Admin link ─────────────────────────────────────────────────────────── */
.admin-link {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-elevated);
    color: var(--text-muted);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    border: 1px solid var(--border);
    opacity: 0.5;
    transition: opacity 0.2s;
    z-index: 50;
}

.admin-link:hover { opacity: 1; }

/* ── Admin styles ───────────────────────────────────────────────────────── */
.admin-body {
    overflow: auto;
    height: auto;
    min-height: 100%;
}

/* PIN screen */
.pin-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.pin-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 40px 32px;
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: var(--shadow-lg);
}

.pin-title {
    font-size: 26px;
    font-weight: 700;
    text-align: center;
}

.pin-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    text-align: center;
}

.pin-input {
    font-family: var(--font);
    font-size: 24px;
    text-align: center;
    letter-spacing: 8px;
    color: var(--text-primary);
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    outline: none;
    width: 100%;
    transition: border-color 0.2s;
}

.pin-input:focus {
    border-color: var(--accent);
}

.pin-btn {
    min-height: var(--touch-lg);
    border-radius: var(--radius-md);
    background: var(--accent);
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    transition: background 0.2s, transform 0.1s;
}

.pin-btn:active {
    transform: scale(0.97);
    background: var(--accent-dark);
}

.pin-error {
    font-size: 14px;
    color: var(--danger);
    text-align: center;
}

.back-link {
    font-size: 15px;
    color: var(--text-muted);
    text-align: center;
    text-decoration: none;
}

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

/* Admin panel */
.admin-panel {
    padding: 0 0 40px;
    max-width: 700px;
    margin: 0 auto;
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
    position: sticky;
    top: 0;
    z-index: 10;
}

.admin-title {
    font-size: 22px;
    font-weight: 700;
}

.admin-header-actions {
    display: flex;
    gap: 10px;
}

.admin-back-btn,
.admin-logout-btn {
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    cursor: pointer;
}

.admin-back-btn {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.admin-logout-btn {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.admin-section {
    padding: 24px;
    border-bottom: 1px solid var(--border);
}

.admin-section-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-size: 13px;
}

.admin-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-input {
    font-family: var(--font);
    font-size: 16px;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
}

.form-input:focus {
    border-color: var(--accent);
}

.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.admin-save-btn {
    font-family: var(--font);
    font-size: 15px;
    font-weight: 700;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    border: none;
    margin-top: 8px;
}

.admin-save-btn:active { transform: scale(0.97); background: var(--accent-dark); }

.admin-test-btn {
    font-family: var(--font);
    font-size: 15px;
    font-weight: 600;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-primary);
    cursor: pointer;
    border: 1px solid var(--border);
    transition: background 0.2s, transform 0.1s;
}

.admin-test-btn:active { transform: scale(0.97); }

.settings-feedback {
    font-size: 14px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-top: 4px;
}

.settings-feedback.success { border-color: var(--success); color: var(--success); }
.settings-feedback.error   { border-color: var(--danger);  color: var(--danger);  }

/* Tile editor cards */
.tile-editor-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tile-editor-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.tile-editor-row .form-row {
    margin: 0;
}

.tile-remove-btn {
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    cursor: pointer;
    align-self: flex-start;
    transition: background 0.2s;
}

.tile-remove-btn:hover {
    background: rgba(231, 76, 60, 0.1);
}

.add-tile-btn {
    font-family: var(--font);
    font-size: 15px;
    font-weight: 700;
    padding: 14px 24px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px dashed var(--border-light);
    cursor: pointer;
    width: 100%;
    margin-bottom: 16px;
    transition: background 0.2s;
}

.add-tile-btn:hover { background: var(--bg-card); }

/* Utility */
.hidden { display: none !important; }
