@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;600;700;800&display=swap');

:root {
    color-scheme: light;
    font-family: "Tajawal", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --ink: #182035;
    --muted: #7f879b;
    --surface: #ffffff;
    --canvas: #f6f7fb;
    --line: #e9eaf1;
    --primary: #7457ee;
    --primary-dark: #6042d8;
    --primary-soft: #eeeafd;
    --success: #20b784;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--canvas); color: var(--ink); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgb(116 87 238 / 24%); outline-offset: 2px; }

.dashboard { margin: 0 auto; max-width: 1280px; padding: 0 44px 56px; }
.topbar { align-items: center; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; min-height: 86px; }
.brand, .top-actions, .metric-card, .device-card-top, .device-footer, .section-heading, .dialog-heading { align-items: center; display: flex; }
.brand { gap: 12px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1.08rem; }
.brand small { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.brand-mark { align-items: center; background: linear-gradient(145deg, #8065f4, #6041cf); border-radius: 14px; box-shadow: 0 8px 18px rgb(116 87 238 / 24%); color: white; display: flex; font-size: 1.2rem; font-weight: 800; height: 44px; justify-content: center; width: 44px; }
.top-actions { gap: 12px; }
.icon-button, .close-button { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: var(--ink); height: 42px; width: 42px; }
.profile-avatar { align-items: center; background: #f0dbbe; border-radius: 50%; display: flex; font-weight: 700; height: 42px; justify-content: center; width: 42px; }
.profile-avatar { color: var(--ink); text-decoration: none; }
.admin-link { color: var(--primary); font-size: .82rem; font-weight: 700; text-decoration: none; }

.welcome-panel { align-items: center; display: flex; justify-content: space-between; padding: 42px 0 30px; }
.eyebrow { color: var(--primary); font-size: .8rem; font-weight: 700; letter-spacing: .02em; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.75rem, 4vw, 2.55rem); margin: 7px 0; }
h2 { font-size: 1.4rem; margin-top: 4px; }
.welcome-panel p { color: var(--muted); }
.primary-button { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); border: 0; border-radius: 13px; box-shadow: 0 9px 18px rgb(116 87 238 / 22%); color: white; font-weight: 700; padding: 13px 20px; }
.primary-button:hover { transform: translateY(-1px); }
.full-width { margin-top: 4px; width: 100%; }

.metrics { display: grid; gap: 16px; grid-template-columns: repeat(3, 1fr); }
.metric-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; gap: 14px; padding: 20px; }
.metric-card::before { border-radius: 4px; content: ""; height: 38px; width: 4px; }
.accent-purple::before { background: var(--primary); }
.accent-green::before { background: var(--success); }
.accent-orange::before { background: #f2a64a; }
.metric-icon { align-items: center; background: var(--primary-soft); border-radius: 13px; color: var(--primary); display: flex; font-size: 1.35rem; height: 44px; justify-content: center; width: 44px; }
.metric-card strong, .metric-card small { display: block; }
.metric-card strong { font-size: 1.4rem; }
.metric-card small { color: var(--muted); margin-top: 2px; }

.content-section { padding-top: 36px; }
.section-heading { justify-content: space-between; margin-bottom: 16px; }
.device-count { color: var(--muted); font-size: .85rem; }
.scenes-grid { display: grid; gap: 16px; grid-template-columns: repeat(3, 1fr); }
.scene-card { align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; color: var(--ink); display: flex; gap: 13px; padding: 18px; text-align: right; }
.scene-card:hover { border-color: #cfc6f8; box-shadow: 0 10px 30px rgb(52 39 101 / 7%); }
.disabled-control { cursor: not-allowed; opacity: .62; }
.scene-icon { align-items: center; background: var(--primary-soft); border-radius: 14px; display: flex; font-size: 1.45rem; height: 48px; justify-content: center; width: 48px; }
.scene-card strong, .scene-card small { display: block; }
.scene-card small { color: var(--muted); font-size: .75rem; margin-top: 4px; }
.scene-arrow { color: var(--muted); margin-inline-start: auto; }

.room-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 14px; scrollbar-width: none; }
.room-tabs button { background: transparent; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); padding: 8px 17px; white-space: nowrap; }
.room-tabs button.active { background: var(--ink); border-color: var(--ink); color: white; }
.devices-grid { display: grid; gap: 16px; grid-template-columns: repeat(4, 1fr); }
.device-card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; min-height: 190px; padding: 19px; transition: transform .15s ease, box-shadow .15s ease; }
.device-card:hover { box-shadow: 0 12px 34px rgb(40 31 80 / 8%); transform: translateY(-2px); }
.device-on { border-color: #ded8f9; }
.device-card-top { justify-content: space-between; }
.device-icon { align-items: center; background: #f1f2f6; border-radius: 14px; display: flex; font-size: 1.35rem; height: 48px; justify-content: center; width: 48px; }
.device-on .device-icon { background: var(--primary-soft); }
.power-switch { background: #d9dbe3; border: 0; border-radius: 999px; height: 28px; padding: 3px; transition: background .15s ease; width: 48px; }
.power-switch span { background: white; border-radius: 50%; box-shadow: 0 1px 5px rgb(0 0 0 / 18%); display: block; height: 22px; transform: translateX(-20px); transition: transform .15s ease; width: 22px; }
.power-switch.on { background: var(--primary); }
.power-switch.on span { transform: translateX(0); }
.locked-control { align-items: center; background: #f1f2f6; border-radius: 50%; display: flex; height: 30px; justify-content: center; width: 30px; }
.device-details { margin-top: 23px; }
.device-details strong, .device-details small { display: block; }
.device-details small { color: var(--muted); font-size: .78rem; margin-top: 5px; }
.device-footer { color: var(--muted); font-size: .75rem; margin-top: 18px; }
.online-dot { background: var(--success); border-radius: 50%; height: 7px; margin-inline-end: 6px; width: 7px; }
.power-usage { margin-inline-start: auto; }

.modal-backdrop { align-items: center; background: rgb(24 32 53 / 42%); display: flex; inset: 0; justify-content: center; padding: 20px; position: fixed; z-index: 20; }
.device-dialog { background: white; border-radius: 22px; box-shadow: 0 30px 80px rgb(24 32 53 / 22%); direction: rtl; padding: 25px; width: min(440px, 100%); }
.dialog-heading { justify-content: space-between; margin-bottom: 22px; }
.device-dialog label { color: #555d70; display: block; font-size: .85rem; margin-top: 14px; }
.device-dialog input, .device-dialog select { background: #fafafe; border: 1px solid var(--line); border-radius: 11px; color: var(--ink); display: block; margin-top: 7px; padding: 11px 12px; width: 100%; }
.form-error { color: #c73b52; font-size: .8rem; margin-top: 10px; }
.toast { background: var(--ink); border-radius: 12px; bottom: 24px; box-shadow: 0 12px 30px rgb(0 0 0 / 18%); color: white; inset-inline-start: 50%; padding: 12px 18px; position: fixed; transform: translateX(-50%); z-index: 30; }

.auth-page { align-items: center; display: flex; justify-content: center; min-height: 100vh; padding: 24px; }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 24px 70px rgb(40 31 80 / 10%); padding: 32px; width: min(460px, 100%); }
.auth-card > .brand-mark { margin-bottom: 20px; }
.auth-brand { align-items: center; color: var(--ink); display: flex; gap: 10px; margin-bottom: 28px; text-decoration: none; }
.auth-card h1 { font-size: 2rem; }
.auth-card > p { color: var(--muted); margin: 8px 0 22px; }
.auth-card label { color: #555d70; display: block; font-size: .85rem; margin-top: 15px; }
.auth-card input:not([type="checkbox"]) { background: #fafafe; border: 1px solid var(--line); border-radius: 11px; color: var(--ink); display: block; margin-top: 7px; padding: 12px; width: 100%; }
.remember-field { align-items: center; display: flex !important; gap: 8px; margin-bottom: 16px; }
.auth-link { color: var(--primary); display: block; font-size: .85rem; margin-top: 20px; text-align: center; }
.auth-button-link { display: block; margin-top: 20px; text-align: center; text-decoration: none; }
.secondary-button { background: white; border: 1px solid var(--line); border-radius: 13px; color: var(--ink); font-weight: 700; margin-top: 12px; padding: 12px 18px; }
.access-denied { padding: 40px; text-align: center; }

.admin-page { margin: 0 auto; max-width: 1050px; padding: 48px 28px; }
.admin-heading { align-items: center; display: flex; justify-content: space-between; margin-bottom: 24px; }
.users-card { background: white; border: 1px solid var(--line); border-radius: 20px; overflow: hidden; }
.user-row { align-items: center; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; padding: 18px 20px; }
.user-row:last-child { border-bottom: 0; }
.user-row strong, .user-row small { display: block; }
.user-row small { color: var(--muted); margin-top: 4px; }
.user-row form, .role-editor { align-items: center; display: flex; gap: 9px; }
.user-row select { background: #fafafe; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }

@media (max-width: 900px) {
    .dashboard { padding-inline: 24px; }
    .devices-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 650px) {
    .dashboard { padding: 0 16px 36px; }
    .topbar { min-height: 72px; }
    .welcome-panel { align-items: flex-start; flex-direction: column; gap: 20px; padding-top: 30px; }
    .welcome-panel .primary-button { width: 100%; }
    .metrics, .scenes-grid { grid-template-columns: 1fr; }
    .metric-card { padding: 15px 17px; }
    .devices-grid { gap: 10px; grid-template-columns: 1fr 1fr; }
    .device-card { min-height: 180px; padding: 15px; }
    .brand small { display: none; }
    .admin-link { display: none; }
    .admin-heading, .user-row { align-items: stretch; flex-direction: column; gap: 14px; }
    .user-row form, .role-editor { align-items: stretch; flex-direction: column; }
}

@media (max-width: 400px) {
    .devices-grid { grid-template-columns: 1fr; }
}
