/* ============================================================
 *  IoT Washer - Mobile-First CSS
 *  Color scheme: Blue/White (water/clean theme)
 * ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #2196F3;
    --primary-dark: #1976D2;
    --primary-light: #BBDEFB;
    --success: #4CAF50;
    --success-dark: #388E3C;
    --danger: #f44336;
    --danger-dark: #D32F2F;
    --warning: #FF9800;
    --gray-50: #FAFAFA;
    --gray-100: #F5F5F5;
    --gray-200: #EEEEEE;
    --gray-300: #E0E0E0;
    --gray-400: #BDBDBD;
    --gray-600: #757575;
    --gray-800: #424242;
    --gray-900: #212121;
    --white: #FFFFFF;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --nav-height: 64px;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    min-height: 100vh;
    padding-bottom: calc(var(--nav-height) + 16px);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary);
    text-decoration: none;
}

/* --- Auth Pages --- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.auth-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 32px 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.auth-logo {
    text-align: center;
    margin-bottom: 24px;
}

.logo-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 8px;
}

.auth-logo h1 {
    font-size: 1.5rem;
    color: var(--gray-900);
    margin-bottom: 4px;
}

.auth-subtitle {
    color: var(--gray-600);
    font-size: 0.9rem;
}

.auth-link {
    text-align: center;
    margin-top: 16px;
    color: var(--gray-600);
    font-size: 0.9rem;
}

/* --- Forms --- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: border-color 0.2s;
    background: var(--white);
    color: var(--gray-900);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.error-msg {
    background: #FFEBEE;
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 12px;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 48px;
}

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

.btn-primary {
    background: var(--primary);
    color: var(--white);
}
.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: var(--white);
}
.btn-success:hover {
    background: var(--success-dark);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}
.btn-danger:hover {
    background: var(--danger-dark);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-800);
}
.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-outline-danger {
    background: transparent;
    color: var(--danger);
    border: 2px solid var(--danger);
}
.btn-outline-danger:hover {
    background: #FFEBEE;
}

.btn-full {
    width: 100%;
    display: flex;
}

.btn-half {
    flex: 1;
}

.action-buttons {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

/* --- Page Header --- */
.page-header {
    padding: 16px;
    background: var(--white);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-header h1 {
    font-size: 1.25rem;
    flex: 1;
}

.back-link {
    font-size: 1.1rem;
    color: var(--primary);
    font-weight: 600;
}

.rename-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    color: var(--gray-600);
}

.greeting {
    color: var(--gray-600);
    font-size: 0.85rem;
}

/* --- Bottom Navigation --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--white);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 200;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--gray-400);
    font-size: 0.7rem;
    padding: 8px 16px;
    transition: color 0.2s;
}

.nav-item.active {
    color: var(--primary);
}

.nav-icon {
    font-size: 1.5rem;
    margin-bottom: 2px;
}

.nav-icon.add-btn {
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: var(--white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-top: -16px;
    box-shadow: 0 2px 8px rgba(33,150,243,0.4);
}

.nav-label {
    font-weight: 500;
}

/* --- Device Grid --- */
.device-grid {
    padding: 16px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

@media (min-width: 600px) {
    .device-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* --- Device Card --- */
.device-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.device-card:active {
    transform: scale(0.98);
}

.device-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.device-card-name {
    font-weight: 600;
    font-size: 1rem;
}

.device-card-status {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 6px rgba(76,175,80,0.5);
}

.status-dot.offline {
    background: var(--gray-400);
}

.device-card-info {
    color: var(--gray-600);
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.device-card-progress {
    display: flex;
    align-items: center;
    gap: 8px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.5s;
}

.progress-text-sm {
    font-size: 0.8rem;
    color: var(--gray-600);
    white-space: nowrap;
}

.device-card-error {
    margin-top: 8px;
    padding: 6px 10px;
    background: #FFEBEE;
    color: var(--danger);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
}

.empty-icon {
    font-size: 64px;
    display: block;
    margin-bottom: 16px;
}

.empty-state h2 {
    color: var(--gray-800);
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--gray-600);
    margin-bottom: 24px;
}

/* --- Section Card --- */
.section-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    margin: 16px;
    box-shadow: var(--shadow);
}

.section-card h2 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.section-card p {
    color: var(--gray-600);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

/* --- Add Device --- */
.add-confirm-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 32px 20px;
    margin: 16px;
    box-shadow: var(--shadow);
    text-align: center;
}

.confirm-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.mac-display {
    font-family: monospace;
    font-size: 1.1rem;
    color: var(--primary);
    background: var(--primary-light);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    margin: 16px 0;
    display: inline-block;
}

.divider {
    display: flex;
    align-items: center;
    margin: 8px 16px;
    color: var(--gray-400);
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--gray-300);
}

.divider span {
    padding: 0 12px;
    font-size: 0.85rem;
}

/* QR Scanner */
.qr-reader {
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 12px;
}

.scan-result {
    padding: 12px;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    margin-top: 12px;
    font-size: 0.9rem;
}

/* --- Device Detail: Status Card --- */
.status-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    margin: 16px;
    box-shadow: var(--shadow);
    text-align: center;
}

.status-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    font-weight: 500;
}

/* Circular Progress Ring */
.progress-ring-container {
    position: relative;
    width: 140px;
    height: 140px;
    margin: 0 auto 20px;
}

.progress-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.progress-ring-bg {
    fill: none;
    stroke: var(--gray-200);
    stroke-width: 8;
}

.progress-ring-fill {
    fill: none;
    stroke: var(--primary);
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.5s;
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.progress-percent {
    display: block;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--gray-900);
}

.progress-time {
    display: block;
    font-size: 0.85rem;
    color: var(--gray-600);
}

/* Status Info */
.status-info {
    text-align: left;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-200);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--gray-600);
    font-size: 0.9rem;
}

.info-value {
    font-weight: 600;
    font-size: 0.9rem;
}

/* Error Banner */
.error-banner {
    margin-top: 16px;
    padding: 12px;
    background: #FFEBEE;
    color: var(--danger);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.error-icon {
    font-size: 1.2rem;
}

/* --- Controls Card --- */
.controls-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    margin: 16px;
    box-shadow: var(--shadow);
}

.controls-card h2 {
    font-size: 1.1rem;
    margin-bottom: 16px;
}

.control-group {
    margin-bottom: 12px;
}

.control-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 6px;
}

.control-group select {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--white);
    color: var(--gray-900);
    cursor: pointer;
}

.control-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.command-feedback {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    text-align: center;
}

.command-feedback.success {
    background: #E8F5E9;
    color: var(--success-dark);
}

.command-feedback.error {
    background: #FFEBEE;
    color: var(--danger);
}

/* --- Danger Zone --- */
.danger-zone {
    border: 2px solid #FFCDD2;
}

.danger-zone h3 {
    color: var(--danger);
    font-size: 0.95rem;
    margin-bottom: 12px;
}

/* --- Loading --- */
.loading-spinner {
    text-align: center;
    padding: 32px;
    color: var(--gray-600);
}

/* --- Error Page --- */
.error-page {
    text-align: center;
    padding: 48px 24px;
}

/* --- Toast Notification --- */
.toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 16px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--gray-900);
    color: var(--white);
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 0.9rem;
    z-index: 300;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
    box-shadow: var(--shadow-lg);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

/* --- Responsive: Tablet + Desktop --- */
@media (min-width: 768px) {
    #app {
        max-width: 600px;
        margin: 0 auto;
    }

    /* Admin pages get wider layout */
    body.admin-mode #app {
        max-width: 960px;
    }

    .bottom-nav {
        max-width: 600px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 16px 16px 0 0;
    }

    body.admin-mode .bottom-nav {
        max-width: 960px;
    }

    .auth-card {
        padding: 40px 32px;
    }
}

/* ============================================================
 *  Admin Console Styles
 * ============================================================ */

/* --- Admin Tabs --- */
.admin-tabs {
    display: flex;
    overflow-x: auto;
    background: var(--white);
    border-bottom: 2px solid var(--gray-200);
    padding: 0 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.admin-tabs::-webkit-scrollbar {
    display: none;
}

.admin-tab {
    flex-shrink: 0;
    padding: 12px 16px;
    border: none;
    background: none;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-600);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}

.admin-tab:hover {
    color: var(--primary);
}

.admin-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* --- Admin Toolbar --- */
.admin-toolbar {
    display: flex;
    justify-content: flex-end;
    padding: 8px 16px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.auto-refresh-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--gray-600);
    cursor: pointer;
}

.auto-refresh-toggle input {
    cursor: pointer;
}

/* --- Admin Panel --- */
.admin-panel {
    padding: 16px;
}

/* --- Stats Grid --- */
.admin-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (min-width: 600px) {
    .admin-stats-grid {
        grid-template-columns: 1fr 1fr 1fr 1fr;
    }
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-card.stat-online {
    border-left: 4px solid var(--success);
}

.stat-card.stat-error {
    border-left: 4px solid var(--danger);
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--gray-600);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* --- Admin Tables --- */
.admin-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--white);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 500px;
}

.admin-table thead {
    background: var(--gray-100);
    position: sticky;
    top: 0;
    z-index: 1;
}

.admin-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--gray-800);
    white-space: nowrap;
    border-bottom: 2px solid var(--gray-200);
}

.admin-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-800);
    vertical-align: middle;
}

.admin-table tbody tr:hover {
    background: var(--gray-50);
}

.admin-table code {
    font-size: 0.8rem;
    background: var(--gray-100);
    padding: 2px 6px;
    border-radius: 4px;
    word-break: break-all;
}

/* --- Admin Filters --- */
.admin-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.admin-filters select {
    padding: 8px 12px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    background: var(--white);
    color: var(--gray-800);
    cursor: pointer;
}

.admin-filters select:focus {
    outline: none;
    border-color: var(--primary);
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-success {
    background: #E8F5E9;
    color: #2E7D32;
}

.badge-error {
    background: #FFEBEE;
    color: #C62828;
}

.badge-admin {
    background: #E3F2FD;
    color: #1565C0;
}

.badge-user {
    background: var(--gray-100);
    color: var(--gray-600);
}

.badge-pending {
    background: #FFF8E1;
    color: #F57F17;
}

.badge-type {
    background: #F3E5F5;
    color: #7B1FA2;
}

/* --- Direction Indicators --- */
.dir-in {
    color: #2E7D32;
    font-weight: 600;
    font-size: 0.8rem;
}

.dir-out {
    color: #1565C0;
    font-weight: 600;
    font-size: 0.8rem;
}

/* --- Pagination --- */
.admin-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 0;
}

.page-btn {
    padding: 8px 16px;
    background: var(--primary);
    color: var(--white);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.page-btn:hover {
    background: var(--primary-dark);
}

.page-info {
    font-size: 0.85rem;
    color: var(--gray-600);
}

/* --- Admin Device Cards --- */
.admin-devices-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

@media (min-width: 600px) {
    .admin-devices-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.admin-device-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.admin-device-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.admin-device-header strong {
    font-family: monospace;
    font-size: 0.95rem;
}

.admin-device-info {
    font-size: 0.85rem;
    color: var(--gray-600);
    line-height: 1.6;
}

.admin-device-info code {
    font-size: 0.8rem;
    background: var(--gray-100);
    padding: 2px 6px;
    border-radius: 4px;
}
