/* ============================================
   Device Internet Blocker - Custom Styles
   Mobile-first, dark theme
   ============================================ */

/* --- Toast notifications --- */
.toast {
    position: fixed;
    top: 1rem;
    right: 1rem;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 9999;
    background: #333;
    color: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    max-width: 90vw;
}
.toast.success { background: #2e7d32; }
.toast.error { background: #c62828; }

/* --- Login --- */
.login-container {
    max-width: 400px;
    margin-top: 10vh;
}
.error-msg {
    color: var(--pico-del-color, #e53935);
    font-weight: 600;
}

/* --- Navigation --- */
nav .brand {
    text-decoration: none;
    font-size: 1.1rem;
}
nav ul {
    gap: 0.5rem;
}
.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid var(--pico-primary);
    background: var(--pico-primary);
    color: var(--pico-primary-inverse);
    display: inline-block;
    text-decoration: none;
    text-align: center;
    white-space: nowrap;
    min-height: 32px;
    line-height: 1.4;
}
.btn-sm.outline {
    background: transparent;
    color: var(--pico-primary);
}
.btn-sm.success {
    background: #2e7d32;
    border-color: #2e7d32;
    color: #fff;
}
.btn-sm.danger {
    background: #c62828;
    border-color: #c62828;
    color: #fff;
}
.btn-sm:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* --- Dashboard header --- */
.dash-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.dash-header h2 {
    margin: 0;
}
.dash-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.search-input {
    max-width: 220px;
    margin: 0;
}
.category-filter {
    max-width: 180px;
    margin: 0;
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
}

/* --- Filter tabs --- */
.filter-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.filter-tabs button {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    border-radius: 20px;
    border: 1px solid var(--pico-muted-border-color);
    background: transparent;
    color: var(--pico-muted-color);
    cursor: pointer;
    min-height: 36px;
}
.filter-tabs button.active {
    background: var(--pico-primary);
    color: var(--pico-primary-inverse);
    border-color: var(--pico-primary);
}
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 12px;
    font-weight: 600;
}
.badge.success { background: #2e7d32; color: #fff; }
.badge.danger { background: #c62828; color: #fff; }
.badge.warning { background: #e65100; color: #fff; }

/* --- Status dot --- */
.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}
.dot.online { background: #4caf50; }
.dot.offline { background: #616161; }

/* --- Device table (desktop) --- */
.table-wrap {
    overflow-x: auto;
}
.device-table {
    font-size: 0.9rem;
}
.device-table td, .device-table th {
    padding: 0.4rem 0.6rem;
    white-space: nowrap;
}

/* --- Device cards (mobile) --- */
.device-cards {
    display: none;
}
.device-card {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border-left: 4px solid #4caf50;
}
.device-card.blocked {
    border-left-color: #c62828;
}

/* --- Bulk selection --- */
.select-col {
    width: 36px;
    text-align: center;
}
.select-col input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}
.device-table tr.selected {
    background: rgba(66, 165, 245, 0.12);
}
.device-card.selected {
    border-color: #42a5f5;
    box-shadow: 0 0 0 1px #42a5f5;
}
.card-checkbox {
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
}

/* --- Bulk action bar --- */
.bulk-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: #1e1e1e;
    border-top: 1px solid var(--pico-muted-border-color);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    gap: 1rem;
}
.bulk-bar-top {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.bulk-bar-count {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
}
.bulk-bar-select-all {
    font-size: 0.8rem !important;
    padding: 0.25rem 0.6rem !important;
    min-height: 28px !important;
}
.bulk-bar-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Card tappable in selection mode */
.device-card.selectable {
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(66, 165, 245, 0.15);
}
.device-card.selectable:active {
    background: rgba(66, 165, 245, 0.08);
}

/* Bottom padding when bulk bar is visible */
.device-cards.has-bulk-bar {
    padding-bottom: 5rem;
}

/* --- Category icon --- */
.cat-icon {
    font-size: 1.1rem;
    line-height: 1;
}

/* --- Category separators --- */
.category-separator td {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--pico-muted-color);
    padding: 0.6rem 0.6rem 0.2rem !important;
    border-bottom: 1px solid var(--pico-muted-border-color);
    background: transparent !important;
    letter-spacing: 0.03em;
}
.category-divider {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--pico-muted-color);
    padding: 0.6rem 0 0.2rem;
    border-bottom: 1px solid var(--pico-muted-border-color);
    margin-top: 0.5rem;
    letter-spacing: 0.03em;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}
.card-header a {
    text-decoration: none;
}
.card-meta {
    font-size: 0.8rem;
    color: var(--pico-muted-color);
    margin-bottom: 0.5rem;
}
.card-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* --- Log cards (mobile) --- */
.log-cards {
    display: none;
}
.log-card {
    padding: 0.6rem;
    margin-bottom: 0.4rem;
}
.log-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

/* --- Device detail --- */
.device-info-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.device-info-actions {
    display: flex;
    gap: 0.5rem;
}
.inline-edit {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
}
.inline-edit input, .inline-edit select {
    margin: 0;
    max-width: 200px;
}

/* --- Schedules --- */
.schedule-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--pico-muted-border-color);
    flex-wrap: wrap;
    gap: 0.5rem;
}
.schedule-info {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}
.schedule-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.day-buttons {
    display: flex;
    gap: 0.3rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

/* --- Toggle switch --- */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    margin: 0;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #616161;
    border-radius: 24px;
    transition: 0.3s;
}
.toggle-slider::before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: 0.3s;
}
.toggle-switch input:checked + .toggle-slider {
    background-color: #4caf50;
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* --- Settings page --- */
.muted-text {
    color: var(--pico-muted-color);
    display: block;
}
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    gap: 1rem;
}
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}
.section-header h3 {
    margin: 0;
}
.allowed-devices-list {
    margin-bottom: 1rem;
}
.allowed-device-card {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 8px;
    gap: 0.75rem;
}
.allowed-device-info {
    flex: 1;
    min-width: 0;
}
.allowed-device-info strong {
    display: block;
    margin-bottom: 0.15rem;
}
.allowed-device-info small {
    display: block;
    margin-bottom: 0.3rem;
    word-break: break-all;
}
.ts-node-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    font-size: 0.85rem;
}
.ts-label {
    font-weight: 500;
    white-space: nowrap;
}
.ts-node-display {
    cursor: pointer;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    border: 1px dashed var(--pico-muted-border-color);
    min-width: 100px;
}
.ts-not-set {
    font-style: italic;
}
.ts-node-edit {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
}
.ts-node-select {
    margin: 0;
    padding: 0.25rem 0.4rem;
    font-size: 0.85rem;
    max-width: 220px;
}
.add-device-section {
    margin-top: 1rem;
}
.add-device-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem 0;
}
.add-device-picker label,
.add-device-manual label {
    display: block;
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
    color: var(--pico-muted-color);
}
.device-picker-select,
.manual-mac-input {
    margin: 0;
    max-width: 400px;
}
.empty-state {
    padding: 1.5rem;
    text-align: center;
    color: var(--pico-muted-color);
    font-style: italic;
}
.ts-info {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.9rem;
}

/* --- Footer --- */
footer {
    margin-top: 2rem;
    text-align: center;
    opacity: 0.7;
}

/* ============================================
   RESPONSIVE: Mobile (< 768px)
   ============================================ */
@media (max-width: 768px) {
    /* Hide desktop table, show cards */
    .table-wrap {
        display: none;
    }
    .device-cards {
        display: block;
    }
    .log-cards {
        display: block;
    }
    .log-cards + .table-wrap,
    .log-cards ~ .table-wrap {
        display: none;
    }

    /* Also hide the log table on mobile */
    table[role="grid"] {
        display: none;
    }

    .dash-header {
        flex-direction: column;
        align-items: stretch;
    }
    .dash-actions {
        width: 100%;
    }
    .search-input {
        max-width: 100%;
        flex: 1;
    }
    .category-filter {
        max-width: 100%;
        flex: 1;
    }

    /* Bigger touch targets on mobile */
    .btn-sm {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        min-height: 44px;
    }
    .card-actions {
        gap: 0.5rem;
    }
    .card-actions .btn-sm {
        flex: 1;
        min-width: 0;
    }

    .device-info-header {
        flex-direction: column;
    }

    .schedule-row {
        flex-direction: column;
        align-items: flex-start;
    }

    nav ul {
        gap: 0.25rem;
    }
    nav ul li a, nav ul li button {
        font-size: 0.85rem;
        padding: 0.2rem 0.4rem;
    }

    .toast {
        left: 1rem;
        right: 1rem;
        text-align: center;
    }

    /* Bulk bar mobile */
    .bulk-bar {
        flex-direction: column;
        padding: 0.6rem 1rem;
        gap: 0.5rem;
    }
    .bulk-bar-top {
        width: 100%;
        justify-content: space-between;
    }
    .bulk-bar-select-all {
        min-height: 36px !important;
        padding: 0.35rem 0.75rem !important;
        font-size: 0.85rem !important;
    }
    .bulk-bar-actions {
        width: 100%;
    }
    .bulk-bar-actions .btn-sm {
        flex: 1;
    }

    /* Bigger checkbox touch target on mobile */
    .card-checkbox {
        width: 22px;
        height: 22px;
    }

    /* More visible selection state on mobile */
    .device-card.selected {
        background: rgba(66, 165, 245, 0.1);
        border-color: #42a5f5;
        border-left-width: 4px;
        border-left-style: solid;
        border-left-color: #42a5f5;
    }

    /* Settings page mobile */
    .setting-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .allowed-device-card {
        flex-direction: column;
    }
    .ts-node-select {
        max-width: 100%;
    }
    .ts-node-edit {
        width: 100%;
    }
    .ts-node-edit select {
        flex: 1;
    }
    .device-picker-select,
    .manual-mac-input {
        max-width: 100%;
    }
}

/* Hide columns on mobile via class */
@media (max-width: 900px) {
    .hide-mobile {
        display: none;
    }
}
