/* MatkulDesk visual refresh: calm base, expressive accents, no visual clutter. */
:root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --panel2: #edf0f7;
    --ink: #20243a;
    --muted: #687087;
    --line: #e2e5ef;
    --blue: #423A8E;
    --blue2: #eeecfa;
    --cyan: #00CCCD;
    --green: #198754;
    --red: #DC3545;
    --amber: #FFC107;
    --shadow: 0 10px 30px rgba(39, 45, 35, .055);
    --sidebar: #423A8E;
    --radius-card: 17px;
}
body {
    letter-spacing: -.01em;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .brand-name, .stat-value, .focus-clock {
    letter-spacing: -.045em;
}
.sidebar {
    background: var(--sidebar);
}
.brand {
    padding-bottom: 22px;
}
.brand-icon {
    border-radius: 13px;
}
.nav-item {
    border-radius: 10px;
    transition: background .18s ease, color .18s ease, transform .18s ease;
}
.nav-item:hover {
    transform: translateX(2px);
}
.nav-item.active {
    background: rgba(255, 255, 255, .11);
}
.topbar {
    backdrop-filter: blur(16px);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    border-bottom: 1px solid var(--line);
}
.view {
    max-width: 1600px;
}
.welcome {
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--panel);
    padding: clamp(20px, 3vw, 30px);
    box-shadow: var(--shadow);
}
.welcome h1 {
    font-size: clamp(25px, 3vw, 34px);
}
.panel, .stat, .card, .device-card {
    border-radius: var(--radius-card);
    box-shadow: var(--shadow);
}
.panel {
    padding: 20px;
}
.stat {
    border: 1px solid var(--line);
}
.btn, .round-btn, .mobile-toggle, .action, .link-btn {
    transition: transform .18s ease, background .18s ease, border-color .18s ease;
}
.btn:hover, .round-btn:hover {
    transform: translateY(-1px);
}
.btn.primary {
    background: var(--blue);
    box-shadow: 0 5px 14px color-mix(in srgb, var(--blue) 22%, transparent);
}
.empty {
    border: 1px dashed var(--line);
    border-radius: 13px;
    padding: 24px 16px;
    color: var(--muted);
}
.settings-panel {
    max-width: 900px;
}
.settings-section-head h3 {
    margin: 7px 0 4px;
    font: 700 20px 'Space Grotesk', sans-serif;
}
.settings-section-head p {
    margin: 0 0 18px;
    color: var(--muted);
    font-size: 12px;
}
.theme-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.theme-option {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 12px;
    text-align: left;
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 13px;
}
.theme-option:hover {
    border-color: var(--blue);
}
.theme-option.selected {
    border-color: var(--blue);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--blue) 13%, transparent);
}
.theme-preview {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    flex: 0 0 62px;
    height: 44px;
    padding: 7px;
    border: 1px solid rgba(0, 0, 0, .08);
    border-radius: 9px;
}
.theme-preview i {
    display: block;
    height: 28px;
    flex: 1;
    border-radius: 4px;
    background: rgba(255, 255, 255, .7);
}
.theme-preview i:first-child {
    flex: 1.4;
}
.theme-preview-paper {
    background: #f1efe8;
}
.theme-preview-paper i:first-child {
    background: #5268e8;
}
.theme-preview-midnight {
    background: #101a20;
}
.theme-preview-midnight i {
    background: #263640;
}
.theme-preview-midnight i:first-child {
    background: #91a6ff;
}
.theme-preview-matcha {
    background: #e8eee2;
}
.theme-preview-matcha i {
    background: #fffdf4;
}
.theme-preview-matcha i:first-child {
    background: #62866b;
}
.theme-preview-berry {
    background: #f2eaf0;
}
.theme-preview-berry i {
    background: #fff9fc;
}
.theme-preview-berry i:first-child {
    background: #985b83;
}
.theme-option-copy {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}
.theme-option-copy b {
    font-size: 12px;
}
.theme-option-copy small {
    color: var(--muted);
    font-size: 10px;
    line-height: 1.4;
}
.theme-check {
    color: var(--blue);
    opacity: 0;
    font-weight: 800;
}
.theme-option.selected .theme-check {
    opacity: 1;
}
.settings-divider {
    height: 1px;
    margin: 22px 0 8px;
    background: var(--line);
}
/* Brand palette inspired by the supplied reference: violet + bright cyan. */
body[data-theme="paper"], body:not([data-theme]), body[data-theme="light"] {
    --bg:#f4f6fb; --panel:#ffffff; --panel2:#eef0f7; --ink:#20243a; --muted:#687087;
    --line:#e2e5ef; --blue:#423A8E; --blue2:#eeecfa; --cyan:#00CCCD;
    --green:#198754; --red:#DC3545; --amber:#FFC107; --sidebar:#423A8E;
    --shadow:0 10px 28px rgba(44,39,105,.10);
}
body[data-theme="matcha"] {
    --bg:#f0f6ef; --panel:#ffffff; --panel2:#e4efe2; --ink:#193b27; --muted:#587060;
    --line:#d2e2d1; --blue:#423A8E; --blue2:#eeecfa; --cyan:#00CCCD;
    --green:#198754; --red:#DC3545; --amber:#FFC107; --sidebar:#315d43;
    --shadow:0 10px 28px rgba(31,83,43,.10);
}
body[data-theme="berry"] {
    --bg:#f5f1f8; --panel:#ffffff; --panel2:#eee7f3; --ink:#342744; --muted:#756783;
    --line:#e0d6e9; --blue:#423A8E; --blue2:#eeecfa; --cyan:#00CCCD;
    --green:#198754; --red:#DC3545; --amber:#FFC107; --sidebar:#423A8E;
    --shadow:0 10px 28px rgba(66,45,89,.10);
}
body[data-theme="midnight"] {
    --bg:#101326; --panel:#191d36; --panel2:#24294a; --ink:#f3f4ff; --muted:#b8bdd8;
    --line:#353a5d; --blue:#8d85e8; --blue2:#302d59; --cyan:#00CCCD;
    --green:#35b77b; --red:#ff6575; --amber:#ffd45c; --sidebar:#0c0e20;
    --shadow:0 12px 35px rgba(0,0,0,.30);
}
body[data-theme="paper"] .nav-item.active,
body[data-theme="matcha"] .nav-item.active,
body[data-theme="berry"] .nav-item.active {background:#00CCCD;color:#17213b;}
body[data-theme="paper"] .btn.primary,
body[data-theme="matcha"] .btn.primary,
body[data-theme="berry"] .btn.primary {background:#423A8E;color:#fff;}
body[data-theme="paper"] .brand-icon,
body[data-theme="matcha"] .brand-icon,
body[data-theme="berry"] .brand-icon {background:#423A8E;color:#fff;}
body[data-theme="midnight"] .nav-item.active {background:#423A8E;color:#fff;}
body[data-theme="midnight"] .btn.primary {background:#00aeb2;color:#071b2a;}
body[data-theme="midnight"] .stat:after {background:#24294a;}
body[data-theme="midnight"] .tag.done {background:#174b3b;color:#8af0bd;}
body[data-theme="midnight"] .tag.high {background:#5b2937;color:#ffb3bb;}
body[data-theme="midnight"] .tag.medium {background:#594322;color:#ffda91;}
body[data-theme="midnight"] .sensor {background:var(--panel2);}
body[data-theme="midnight"] .toggle {background:#536a80;}

/* Midnight: dense star field drifting upward, with no interaction blocking. */
body[data-theme="midnight"] {
    position: relative;
    isolation: isolate;
}
body[data-theme="midnight"]::before,
body[data-theme="midnight"]::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-repeat: repeat;
    will-change: background-position;
}
body[data-theme="midnight"]::before {
    opacity: .72;
    background-image:
      radial-gradient(1.4px 1.4px at 12px 18px, #ffffff 98%, transparent),
      radial-gradient(1px 1px at 65px 82px, #a9d5ff 98%, transparent),
      radial-gradient(1.6px 1.6px at 132px 44px, #ffffff 98%, transparent),
      radial-gradient(1px 1px at 190px 122px, #d9ecff 98%, transparent),
      radial-gradient(1.3px 1.3px at 245px 16px, #ffffff 98%, transparent),
      radial-gradient(1px 1px at 302px 96px, #8ebeff 98%, transparent),
      radial-gradient(1.5px 1.5px at 358px 58px, #ffffff 98%, transparent),
      radial-gradient(1px 1px at 414px 140px, #c5e3ff 98%, transparent);
    background-size: 470px 170px;
    animation: md-stars-rise 34s linear infinite;
}
body[data-theme="midnight"]::after {
    opacity: .48;
    background-image:
      radial-gradient(2px 2px at 28px 70px, #ffffff 98%, transparent),
      radial-gradient(1.2px 1.2px at 100px 130px, #8dc5ff 98%, transparent),
      radial-gradient(1.8px 1.8px at 174px 24px, #ffffff 98%, transparent),
      radial-gradient(1px 1px at 224px 102px, #d5eaff 98%, transparent),
      radial-gradient(1.6px 1.6px at 290px 48px, #ffffff 98%, transparent),
      radial-gradient(1px 1px at 368px 150px, #8dc5ff 98%, transparent),
      radial-gradient(1.4px 1.4px at 430px 88px, #ffffff 98%, transparent);
    background-size: 510px 190px;
    animation: md-stars-rise 22s linear infinite;
}
@keyframes md-stars-rise {
    from { background-position: 0 0; }
    to { background-position: 0 -760px; }
}
body[data-theme="midnight"] .layout {
    position: relative;
    z-index: 0;
}
body[data-theme="midnight"] .topbar {
    background: rgba(7, 20, 38, .88);
}
@media (max-width: 620px) {
    .theme-options {
        grid-template-columns: 1fr;
    }
    .panel {
        padding: 15px;
    }
    .welcome {
        border-radius: 15px;
    }
}

/* Clickable account shortcuts */
.topbar-profile-btn{
  border:0;
  padding:0;
  cursor:pointer;
  font:inherit;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}
.topbar-profile-btn:focus-visible,
.user-card:focus-visible{
  outline:3px solid var(--accent, #7c8cff);
  outline-offset:3px;
}
.user-card{
  width:100%;
  border:0;
  text-align:left;
  cursor:pointer;
  font:inherit;
}


/* Theme selector previews */
.theme-preview-paper { background:#dce9ff; }
.theme-preview-paper i:first-child { background:#155eef; }
.theme-preview-matcha { background:#d2e5c8; }
.theme-preview-matcha i { background:#fafff6; }
.theme-preview-matcha i:first-child { background:#287a43; }
.theme-preview-midnight { background:#071426; }
.theme-preview-midnight i { background:#193452; }
.theme-preview-midnight i:first-child { background:#72a7ff; }
.theme-preview-berry { background:#ead7e6; }
.theme-preview-berry i { background:#fffaff; }
.theme-preview-berry i:first-child { background:#963b78; }

@media (prefers-reduced-motion: reduce) {
    body[data-theme="midnight"]::before,
    body[data-theme="midnight"]::after {
        animation: none;
    }
}

/* Reference palette swatches */
.theme-preview-paper i:first-child,.theme-preview-matcha i:first-child,.theme-preview-berry i:first-child{background:#423A8E!important}
.theme-preview-paper i:nth-child(2),.theme-preview-matcha i:nth-child(2),.theme-preview-berry i:nth-child(2){background:#00CCCD!important}

/* Responsive layout refinements: fluid desktop, tablet and mobile */
.layout{width:100%;min-width:0;}
.sidebar{height:100dvh;min-height:0;display:flex;flex-direction:column;}
.sidebar-scroll{min-height:0;flex:1 1 auto;overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch;}
.main{min-width:0;width:calc(100% - 252px);}
.view{min-width:0;width:100%;padding-left:clamp(14px,2.6vw,36px);padding-right:clamp(14px,2.6vw,36px);}
img,svg,canvas,video{max-width:100%;}
.panel,.stat,.card,.device-card,.welcome,.admin-hero{min-width:0;}
.table-wrap{max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;}
.data-table{width:100%;}
button,a,input,select,textarea{touch-action:manipulation;}
.sidebar-backdrop{transition:opacity .22s ease;}
@media(max-width:1100px){
 .sidebar{width:224px;min-width:224px;}
 .main{width:calc(100% - 224px);margin-left:224px;padding-left:0;}
 .topbar{padding-left:clamp(16px,2.5vw,28px);padding-right:clamp(16px,2.5vw,28px);}
 .view{padding-top:24px;}
 .tri-dashboard{grid-template-columns:repeat(2,minmax(0,1fr));}
 .tri-dashboard .events-card{grid-column:1/-1;min-height:unset;}
}
@media(max-width:720px){
 .layout{display:block!important;}
 .sidebar{position:fixed!important;inset:0 auto 0 0!important;height:100dvh!important;width:min(84vw,310px)!important;min-width:0!important;max-width:calc(100vw - 48px);transform:translateX(-105%);z-index:1000;}
 .sidebar.open{transform:translateX(0);}
 .sidebar-scroll{overflow-y:auto;min-height:0;}
 .main{margin:0!important;padding:0 14px calc(92px + env(safe-area-inset-bottom))!important;width:100%!important;min-width:0!important;}
 .topbar{position:sticky;top:0;height:62px!important;margin:0 -14px 16px!important;padding:0 14px!important;gap:10px;z-index:30;}
 .mobile-toggle{display:inline-flex!important;align-items:center;justify-content:center;flex:0 0 36px;width:36px;height:36px;border:1px solid var(--line);border-radius:10px;background:var(--panel);color:var(--ink);}
 .crumb{min-width:0;flex:1;overflow:hidden;white-space:nowrap;}
 .crumb span,.crumb b{display:none;}
 .crumb strong{font-size:14px;overflow:hidden;text-overflow:ellipsis;}
 .top-date{display:none!important;}
 .topbar-right{gap:8px;}
 .view{padding:10px 0 24px!important;width:100%;}
 .welcome,.welcome-new,.admin-hero{display:flex;flex-direction:column;align-items:flex-start;gap:12px;padding:19px!important;border-radius:17px!important;}
 .welcome h1,.admin-hero h2{font-size:clamp(22px,6vw,28px)!important;line-height:1.2;}
 .welcome .btn,.page-head .btn{width:100%;justify-content:center;}
 .stats{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:10px!important;}
 .stat{padding:13px!important;min-width:0;}
 .stat-value{font-size:clamp(20px,5vw,25px)!important;overflow-wrap:anywhere;}
 .dash-grid{display:grid!important;grid-template-columns:minmax(0,1fr)!important;}
 .tri-dashboard{grid-template-columns:minmax(0,1fr)!important;gap:12px!important;}
 .tri-dashboard .events-card{grid-column:auto;}
 .tri-card{min-height:unset!important;}
 .panel{padding:14px!important;margin-bottom:12px!important;border-radius:15px!important;}
 .page-head{align-items:flex-start!important;flex-wrap:wrap;gap:10px;}
 .page-head h1{font-size:clamp(23px,6vw,28px)!important;}
 .toolbar{display:flex;flex-wrap:wrap;gap:8px;}
 .search{width:100%!important;max-width:none!important;}
 .table-wrap{overflow-x:auto!important;max-width:100%;}
 .data-table{min-width:620px;}
 .form-grid{grid-template-columns:minmax(0,1fr)!important;}
 .field.full{grid-column:auto!important;}
 .modal-layer{padding:8px!important;align-items:flex-end!important;}
 .modal{width:100%!important;max-width:none!important;max-height:88dvh!important;overflow:auto!important;border-radius:19px 19px 10px 10px!important;padding:17px!important;}
 .modal-actions{position:sticky;bottom:-17px;background:var(--panel);padding:12px 0 0;}
 footer{padding:14px 0;font-size:10px;}
 footer span{float:none;display:block;margin-top:5px;}
 .mobile-bottom-nav{left:9px!important;right:9px!important;bottom:calc(8px + env(safe-area-inset-bottom))!important;grid-template-columns:repeat(5,minmax(0,1fr))!important;padding:6px 3px!important;background:color-mix(in srgb,var(--panel) 94%,transparent)!important;border-color:var(--line)!important;}
 .mobile-bottom-nav button{min-width:0;}
 .mobile-bottom-nav button.active{color:var(--cyan)!important;}
}
@media(max-width:390px){
 .main{padding-left:10px!important;padding-right:10px!important;}
 .topbar{margin-left:-10px!important;margin-right:-10px!important;padding-left:10px!important;padding-right:10px!important;}
 .stats{gap:8px!important;}
 .stat{padding:10px!important;}
 .mobile-bottom-nav{left:6px!important;right:6px!important;}
}
@media(prefers-reduced-motion:reduce){*,*::before,*::after{scroll-behavior:auto!important;animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important;}}
