/* ============================================================
   Deye Repair — design system (Deye Cloud–style enterprise SaaS)
   Light + dark themes via CSS variables. Toggle sets
   document.documentElement[data-theme="dark"].
   ============================================================ */

:root {
    --brand: #1E5AA8;
    --brand-dark: #16467f;
    --brand-200: #cfe0f3;
    --brand-50: #e8f0fa;
    --accent-red: #e2231a;

    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f7f9fc;
    --surface-hover: #f0f4f9;
    --text: #1f2933;
    --text-muted: #6b7785;
    --border: #e6eaf0;

    --success: #1f9d57; --success-bg: #e3f5ea;
    --warning: #d98a00; --warning-bg: #fdefd6;
    --danger:  #d64545; --danger-bg:  #fbe3e3;
    --info:    #1E5AA8; --info-bg:    #e8f0fa;

    /* category accents (soft) */
    --cat-inverter: #3b6fb5;     --cat-inverter-bg: #eaf1fb;
    --cat-micro: #4aa3c7;        --cat-micro-bg: #e6f4f9;
    --cat-battery: #2f9e6a;      --cat-battery-bg: #e6f6ee;
    --cat-ess: #d98a00;          --cat-ess-bg: #fdf2dc;
    --cat-other: #7a5cc0;        --cat-other-bg: #efeafb;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(16,40,80,.08), 0 1px 2px rgba(16,40,80,.05);
    --shadow-lg: 0 8px 28px rgba(16,40,80,.16);
    --nav-h: 60px;
}

[data-theme="dark"] {
    --brand: #4f8fd6;
    --brand-dark: #3b78bd;
    --brand-200: #2f4a66;
    --brand-50: #16314f;

    --bg: #0f141a;
    --surface: #1a212b;
    --surface-2: #212a35;
    --surface-hover: #273140;
    --text: #e6eaf0;
    --text-muted: #9aa7b5;
    --border: #2c3744;

    --success-bg: #16331f; --warning-bg: #3a2c10; --danger-bg: #3a1d1d; --info-bg: #16314f;
    --cat-inverter-bg:#16263f; --cat-micro-bg:#152d36; --cat-battery-bg:#13301f; --cat-ess-bg:#352910; --cat-other-bg:#241a3a;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
    --shadow-lg: 0 10px 30px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; font-weight: 600; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; font-weight: 600; }
.muted { color: var(--text-muted); }

/* ---------- Brand / logo ---------- */
.brand-logo { display: inline-flex; align-items: center; gap: .5rem; }
.brand-logo img { height: 30px; width: auto; }

/* Theme-aware logo: primary (blue) on light surfaces, white version on dark. */
.logo-on-light { display: block; }
.logo-on-dark { display: none; }
[data-theme="dark"] .logo-on-light { display: none; }
[data-theme="dark"] .logo-on-dark { display: block; }

/* ---------- Top navigation ---------- */
.topnav {
    position: sticky; top: 0; z-index: 40;
    height: var(--nav-h);
    display: flex; align-items: center; gap: 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.25rem;
}
.topnav .nav-items { display: flex; align-items: center; gap: .25rem; height: 100%; }
.nav-item { position: relative; height: 100%; display: flex; align-items: center; }
.nav-item > a, .nav-item > button {
    height: 100%; display: inline-flex; align-items: center; gap: .35rem;
    padding: 0 .9rem; border: none; background: none; cursor: pointer;
    color: var(--text); font-size: .95rem; font-weight: 500; font-family: inherit;
}
.nav-item > a:hover, .nav-item > button:hover { color: var(--brand); }
.nav-item > a.active, .nav-item.open > button { color: var(--brand); font-weight: 600; }
.nav-item .caret { font-size: .6rem; opacity: .7; }
.topnav .spacer { flex: 1; }

/* mega menu */
.mega { position: absolute; top: var(--nav-h); left: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 1.1rem 1.25rem; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(170px, 1fr); gap: 1.5rem; }
.mega .col h4 { margin: 0 0 .5rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.mega .col a { display: block; padding: .3rem 0; color: var(--text); font-size: .9rem; }
.mega .col a:hover { color: var(--brand); }

/* ---------- Universal search ---------- */
.search { display: flex; align-items: center; gap: .5rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: .4rem .85rem; min-width: 240px; }
.search input { border: none; background: none; outline: none; color: var(--text); font-size: .9rem; width: 100%; }

/* ---------- Profile / avatar ---------- */
.profile { position: relative; }
.avatar-btn { display: flex; align-items: center; gap: .5rem; background: none; border: none; cursor: pointer; padding: .25rem; }
.avatar { position: relative; width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; }
.avatar .status-dot { position: absolute; bottom: 0; right: 0; width: 10px; height: 10px; border-radius: 50%; background: var(--success); border: 2px solid var(--surface); }
.avatar .badge-count { position: absolute; top: -4px; right: -6px; background: var(--danger); color: #fff; font-size: .65rem; font-weight: 700; border-radius: 999px; padding: 0 .3rem; min-width: 16px; text-align: center; }
.dropdown { position: absolute; right: 0; top: calc(var(--nav-h) - 8px); width: 320px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden; }
.dropdown .dd-head { padding: .9rem 1rem; border-bottom: 1px solid var(--border); }
.dropdown .dd-section { padding: .5rem 0; border-bottom: 1px solid var(--border); }
.dropdown .dd-section:last-child { border-bottom: none; }
.dropdown .dd-item { display: flex; align-items: center; gap: .6rem; width: 100%; padding: .55rem 1rem; background: none; border: none; cursor: pointer; color: var(--text); font-size: .9rem; font-family: inherit; text-align: left; }
.dropdown .dd-item:hover { background: var(--surface-hover); }
.dropdown .dd-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); padding: .4rem 1rem .2rem; }
.perspective-chip { font-size: .7rem; padding: .1rem .5rem; border-radius: 999px; background: var(--brand-50); color: var(--brand); }

/* ---------- App shell ---------- */
.app-main { min-height: calc(100vh - var(--nav-h)); }
.content { padding: 1.5rem; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; }
.card h2 { margin-top: 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; }

/* category KPI tiles (Deye Cloud style) */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.cat-tile { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; cursor: pointer; transition: transform .08s ease, box-shadow .12s ease; box-shadow: var(--shadow); }
.cat-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.cat-tile .cat-top { display: flex; align-items: center; gap: .6rem; }
.cat-tile .cat-icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.cat-tile .cat-name { font-weight: 600; }
.cat-tile .cat-total { font-size: 1.9rem; font-weight: 800; margin: .3rem 0 .1rem; }
.cat-tile .cat-metrics { display: flex; gap: 1rem; margin-top: .6rem; }
.cat-tile .cat-metric { font-size: .8rem; color: var(--text-muted); display: flex; flex-direction: column; }
.cat-tile .cat-metric b { font-size: 1rem; color: var(--text); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px; }
.dot.green { background: var(--success); } .dot.orange { background: var(--warning); } .dot.grey { background: var(--text-muted); } .dot.blue { background: var(--brand); }

.tile-inverter { background: var(--cat-inverter-bg); } .tile-inverter .cat-icon { background: var(--cat-inverter); color:#fff; }
.tile-micro { background: var(--cat-micro-bg); } .tile-micro .cat-icon { background: var(--cat-micro); color:#fff; }
.tile-battery { background: var(--cat-battery-bg); } .tile-battery .cat-icon { background: var(--cat-battery); color:#fff; }
.tile-ess { background: var(--cat-ess-bg); } .tile-ess .cat-icon { background: var(--cat-ess); color:#fff; }
.tile-other { background: var(--cat-other-bg); } .tile-other .cat-icon { background: var(--cat-other); color:#fff; }

/* stat cards */
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; }
.stat-num { font-size: 1.9rem; font-weight: 800; color: var(--brand); }
.stat-label { color: var(--text-muted); font-size: .85rem; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin: 1.5rem 0 .6rem; }

/* ---------- Tables ---------- */
table.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.grid th, table.grid td { text-align: left; padding: .65rem .8rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
table.grid th { background: var(--surface-2); font-weight: 600; color: var(--text-muted); }
table.grid tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover { background: var(--surface-hover); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 600; background: var(--info-bg); color: var(--brand-dark); }
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.warn { background: var(--warning-bg); color: var(--warning); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .5rem .9rem; border-radius: var(--radius-sm); font-size: .9rem; font-family: inherit; text-decoration: none; }
.btn:hover { background: var(--surface-hover); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-light { background: var(--surface); }
.btn:disabled { opacity: .6; cursor: default; }

/* ---------- Forms ---------- */
.field { margin-bottom: .85rem; display: flex; flex-direction: column; gap: .3rem; }
.field label { font-size: .82rem; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea { padding: .55rem .65rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .95rem; background: var(--surface); color: var(--text); font-family: inherit; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
.alert-error { background: var(--danger-bg); color: var(--danger); padding: .6rem .8rem; border-radius: var(--radius-sm); margin-bottom: .85rem; font-size: .9rem; }
.alert-ok { background: var(--success-bg); color: var(--success); padding: .6rem .8rem; border-radius: var(--radius-sm); margin-bottom: .85rem; font-size: .9rem; }

.toolbar { display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar input, .toolbar select { padding: .5rem .65rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,30,55,.45); display: flex; align-items: center; justify-content: center; z-index: 60; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; width: 480px; max-width: 92vw; max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg); }

/* ---------- Login (Deye-style auth, dark + light) ---------- */
:root {
    --auth-bg: linear-gradient(135deg, #eef2fb 0%, #ffffff 60%);
    --auth-glow: radial-gradient(50% 55% at 18% 22%, rgba(91,140,255,.18), transparent 70%);
    --auth-word: #16213a; --auth-accent: #1E5AA8; --auth-muted: #6b7785;
    --auth-card: #ffffff; --auth-card-border: #e6eaf0;
    --auth-card-shadow: 0 18px 50px rgba(30,90,168,.14);
    --auth-title-1: #1E5AA8; --auth-title-2: #16467f;
    --auth-label: #41526b; --auth-input: #f5f7fb; --auth-input-border: #dfe5ee;
}
[data-theme="dark"] {
    --auth-bg: #080b12;
    --auth-glow:
        radial-gradient(45% 55% at 16% 20%, rgba(99,102,241,.30), transparent 62%),
        radial-gradient(42% 50% at 88% 92%, rgba(47,107,255,.20), transparent 60%);
    --auth-word: #f3f6fc; --auth-accent: #6ea8ff; --auth-muted: #8a94a6;
    --auth-card: #111722; --auth-card-border: rgba(120,150,220,.18);
    --auth-card-shadow: 0 0 55px rgba(47,107,255,.28), 0 24px 60px rgba(0,0,0,.55);
    --auth-title-1: #cfe0ff; --auth-title-2: #ffffff;
    --auth-label: #e6eaf0; --auth-input: #0a0e16; --auth-input-border: rgba(120,150,220,.20);
}

.auth { position: relative; min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; align-items: center; overflow: hidden; background: var(--auth-bg); font-family: 'Poppins', 'Segoe UI', system-ui, sans-serif; }
.auth::before { content: ""; position: absolute; inset: 0; background: var(--auth-glow); pointer-events: none; }

.auth-theme { position: absolute; top: 1.25rem; right: 1.25rem; z-index: 3; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--auth-card-border); background: var(--auth-card); color: var(--text); cursor: pointer; font-size: 1.05rem; line-height: 1; }

.auth-hero { position: relative; z-index: 2; padding: 0 8%; }
.auth-brand { display: flex; align-items: center; gap: .75rem; }
.auth-brand img { height: 54px; width: auto; }
.auth-brand .word { font-size: 2.6rem; font-weight: 700; letter-spacing: -.01em; }
.auth-brand .w1 { color: var(--auth-word); }
.auth-brand .w2 { color: var(--auth-accent); }
.auth-tag { margin: 1rem 0 0; color: var(--auth-muted); font-size: 1.1rem; }

.auth-panel { position: relative; z-index: 2; display: flex; justify-content: center; padding: 2rem; }
.auth-card { width: 100%; max-width: 440px; background: var(--auth-card); border: 1px solid var(--auth-card-border); border-radius: 18px; padding: 2.75rem 2.5rem; box-shadow: var(--auth-card-shadow); }
.auth-card h2 { text-align: center; font-size: 1.9rem; font-weight: 700; margin: 0 0 2rem; background: linear-gradient(180deg, var(--auth-title-1), var(--auth-title-2)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent; }

.auth-field { margin-bottom: 1.35rem; }
.auth-field label { display: block; color: var(--auth-label); font-weight: 600; font-size: .92rem; margin-bottom: .5rem; }
.auth-field input { width: 100%; padding: .85rem .95rem; border-radius: 10px; background: var(--auth-input); border: 1px solid var(--auth-input-border); color: var(--text); font-size: 1rem; font-family: inherit; }
.auth-field input::placeholder { color: var(--auth-muted); opacity: .7; }
.auth-field input:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.25); }

.auth-btn { width: 100%; margin-top: .5rem; padding: .9rem; border: none; border-radius: 10px; cursor: pointer; font-size: 1.02rem; font-weight: 700; font-family: inherit; color: #fff; background: linear-gradient(180deg, #5b8cff 0%, #2f6bff 100%); box-shadow: 0 8px 22px rgba(47,107,255,.4); }
.auth-btn:hover { filter: brightness(1.06); }
.auth-btn:disabled { opacity: .7; cursor: default; }
.auth-error { background: rgba(214,69,69,.15); color: #ff7a7a; border: 1px solid rgba(214,69,69,.35); padding: .65rem .8rem; border-radius: 10px; margin-bottom: 1rem; font-size: .9rem; }

.auth-foot { position: absolute; bottom: 1.5rem; left: 0; right: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: .15rem; color: var(--auth-muted); }
.auth-foot img { height: 22px; width: auto; }
.auth-foot span { font-weight: 700; color: var(--auth-word); font-size: .95rem; }
.auth-foot small { font-size: .8rem; }

@media (max-width: 900px) { .auth { grid-template-columns: 1fr; } .auth-hero { display: none; } .auth-foot { position: static; margin-top: 1.5rem; } }

/* ---------- Coming soon ---------- */
.coming-soon { text-align: center; padding: 4rem 1rem; color: var(--text-muted); }
.coming-soon .cs-icon { font-size: 3rem; }

/* ---------- Client portal ---------- */
.portal-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; margin-top: 1rem; }

/* ---------- Mobile (phones + small tablets) ---------- */
@media (max-width: 820px) {
    .portal-cols { grid-template-columns: 1fr; }
    .content { padding: .85rem; }
    .page-head h1 { font-size: 1.25rem; }
    .cat-grid { grid-template-columns: 1fr; }

    /* Tables scroll sideways inside the card instead of breaking the page. */
    table.grid { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

    /* Top nav: allow items to shrink; keep tap targets comfortable. */
    .topnav { padding: 0 .6rem; gap: .5rem; }
    .topnav .search { min-width: 0; flex: 1; }
    .nav-item > a, .nav-item > button { padding: 0 .55rem; font-size: .88rem; }

    /* Auth (login / register) pages. */
    .auth { grid-template-columns: 1fr; }
    .auth-card { padding: 1.75rem 1.25rem; }
    .auth-panel { padding: 1rem; }

    .modal { width: 94vw; padding: 1rem; }
    .toolbar { gap: .5rem; }
    .btn { padding: .5rem .7rem; }
}

/* ---------- Misc ---------- */
.activity-item { display: flex; gap: .6rem; padding: .55rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.activity-item:last-child { border-bottom: none; }
.activity-item .when { color: var(--text-muted); font-size: .8rem; white-space: nowrap; }

.kv { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 0; font-size: .9rem; align-items: baseline; }
.kv > div { text-align: right; font-weight: 500; }
