/* Chipford Mobile App - Dark Theme for iPhone */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #1f2b47;
    --bg-card-hover: #263554;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --text-muted: #6b7280;
    --accent: #4f8cff;
    --accent-hover: #3a7aef;
    --success: #34d399;
    --danger: #f87171;
    --warning: #fbbf24;
    --border: #2a3a5c;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ===== Auth Page ===== */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 380px;
}

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

.auth-logo h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 4px;
    color: var(--accent);
}

.auth-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.auth-form {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 24px;
    border: 1px solid var(--border);
}

.auth-info {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.auth-link {
    display: block;
    text-align: center;
    color: var(--accent);
    text-decoration: none;
    font-size: 0.875rem;
    margin-top: 16px;
}

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

.form-group label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

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

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

.form-input-password {
    text-align: center;
    font-size: 1.5rem;
    letter-spacing: 4px;
    font-weight: 600;
}

.form-input-code {
    text-align: center;
    font-size: 1.75rem;
    letter-spacing: 12px;
    font-weight: 600;
}

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

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover, .btn-primary:active {
    background: var(--accent-hover);
}

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

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-full {
    width: 100%;
}

.btn-back {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 1rem;
    cursor: pointer;
    padding: 12px 0;
    margin-bottom: 8px;
}

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.alert-error {
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger);
    border: 1px solid rgba(248, 113, 113, 0.3);
}

.alert-success {
    background: rgba(52, 211, 153, 0.15);
    color: var(--success);
    border: 1px solid rgba(52, 211, 153, 0.3);
}

.alert-warning {
    background: rgba(251, 191, 36, 0.15);
    color: var(--warning);
    border: 1px solid rgba(251, 191, 36, 0.3);
}

/* ===== Header ===== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-title {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--accent);
}

.header-logout {
    color: var(--text-muted);
    display: flex;
    padding: 8px;
}

/* ===== Dashboard ===== */
.dashboard {
    padding: 20px;
    padding-bottom: env(safe-area-inset-bottom, 20px);
}

.menu-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.menu-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-appearance: none;
    appearance: none;
    color: var(--text-primary);
    font-family: inherit;
}

.menu-card:active {
    background: var(--bg-card-hover);
    transform: scale(0.97);
}

.menu-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.menu-label {
    font-size: 0.9rem;
    font-weight: 600;
}

/* ===== Content Area ===== */
.content-area {
    margin-top: 16px;
}

.content-area h2 {
    font-size: 1.125rem;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* ===== Data Cards ===== */
.data-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.data-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.data-row:not(:last-child) {
    border-bottom: 1px solid var(--border);
}

.data-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.data-value {
    font-weight: 600;
    font-size: 1rem;
}

.data-value.positive {
    color: var(--success);
}

.data-value.negative {
    color: var(--danger);
}

.data-total {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 2px solid var(--border);
}

.data-total .data-value {
    font-size: 1.125rem;
    color: var(--accent);
}

/* ===== Device List ===== */
.device-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.device-item:active {
    background: var(--bg-card-hover);
}

.device-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.device-status {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.device-status.on {
    background: var(--success);
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
}

.device-status.off {
    background: var(--danger);
}

.device-name {
    font-size: 0.95rem;
    font-weight: 500;
}

.device-toggle {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== Coffee Menu ===== */
.coffee-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.coffee-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-appearance: none;
    appearance: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    text-align: left;
    width: 100%;
}

.coffee-btn:active {
    background: var(--bg-card-hover);
    transform: scale(0.98);
}

.coffee-emoji {
    font-size: 1.5rem;
}

.coffee-off {
    text-align: center;
    padding: 20px;
}

.coffee-off p {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

/* ===== Info Block (payroll) ===== */
.info-block {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.info-line {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 0.95rem;
}

.info-line .label {
    color: var(--text-secondary);
}

.info-line .value {
    font-weight: 600;
}

.info-result {
    margin-top: 10px;
    padding: 12px;
    border-radius: var(--radius-sm);
    text-align: center;
    font-weight: 600;
}

.info-result.need {
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger);
}

.info-result.ok {
    background: rgba(52, 211, 153, 0.15);
    color: var(--success);
}

/* ===== Network Events ===== */
.event-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    border-left: 3px solid var(--border);
}

.event-up {
    border-left-color: var(--success);
    background: rgba(52, 211, 153, 0.05);
}

.event-down {
    border-left-color: var(--danger);
    background: rgba(248, 113, 113, 0.08);
}

.event-icon {
    font-size: 1rem;
    flex-shrink: 0;
    margin-top: 1px;
}

.event-body {
    flex: 1;
    min-width: 0;
}

.event-msg {
    font-size: 0.85rem;
    line-height: 1.3;
}

.event-time {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ===== Loading ===== */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(26, 26, 46, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Dialog ===== */
.dialog-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(26, 26, 46, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.dialog-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 320px;
}

.dialog-box p {
    text-align: center;
    margin-bottom: 20px;
    font-size: 1rem;
    line-height: 1.5;
}

.dialog-buttons {
    display: flex;
    gap: 12px;
}

.dialog-buttons .btn {
    flex: 1;
}

/* ===== Utilities ===== */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }

/* ===== Safe Area (iPhone notch) ===== */
@supports (padding-top: env(safe-area-inset-top)) {
    .header {
        padding-top: calc(16px + env(safe-area-inset-top));
    }
    .dashboard {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
}

/* ===== Toast Notification ===== */
.toast {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 20px;
    font-size: 0.9rem;
    z-index: 1100;
    opacity: 0;
    transition: all 0.3s ease;
    max-width: 90%;
    text-align: center;
}

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

.toast.toast-success { border-color: rgba(52, 211, 153, 0.5); }
.toast.toast-error { border-color: rgba(248, 113, 113, 0.5); }
