:root {
  --logo-height: 56px;
  --bg: #0a0a0b;            /* black */
  --panel: #111317;         /* near-black panel */
  --panel-2: #171a20;       /* deeper panel */
  --text: #ffffff;          /* white */
  --muted: #c1c6cf;         /* soft grey */
  --brand: #ff2a2a;         /* VR red */
  --accent: #11c784;        /* positive */
  --warning: #f59e0b;
  --danger: #ef4444;        /* negative */
  --shadow: 0 6px 24px rgba(0,0,0,0.45);
  --tile-mobile-h: 84px;    /* unified tile height for mobile */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: auto; min-height: 100vh; width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: radial-gradient(1000px 600px at -10% -20%, #171a22 0%, #0a0a0b 40%), var(--bg);
  color: var(--text);
}

.app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; min-height: 100dvh; height: 100dvh; }

.sidebar {
  background: linear-gradient(180deg, #0c0d10 0%, #0a0b0d 100%);
  border-right: 1px solid #1e2432;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
}
.spacer { flex: 1; }
.sidebar-footer { padding-top: 12px; border-top: 1px solid #1e2432; }
.brand { display: flex; align-items: center; justify-content: center; padding: 12px 8px 20px 8px; }
.brand img {
  height: var(--logo-height);
  width: auto;
  max-width: 90%;
  image-rendering: -webkit-optimize-contrast;
}

.nav { display: grid; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; color: var(--text); text-decoration: none; border-radius: 10px; opacity: 0.9; }
.nav a:hover { background: #171a20; opacity: 1; }
.nav a.active { background: #1a1718; border: 1px solid var(--brand); box-shadow: 0 0 0 1px rgba(255,42,42,0.15) inset; }
.nav .icon { width: 22px; text-align: center; }

/* Mobile nav toggle */
.hamburger { display: none; margin-right: 10px; padding: 8px 10px; border-radius: 10px; border: 1px solid #2a2d36; background: #171a20; color: var(--text); cursor: pointer; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 999; }
.brand-mobile { display: none; align-items: center; margin-right: 10px; }
.brand-mobile img { height: 20px; max-height: 24px; width: auto; display: block; }

.main { display: grid; grid-template-rows: 64px 1fr; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-bottom: 1px solid #21242c; backdrop-filter: blur(8px); background: rgba(16, 18, 24, 0.65); }
.topbar .search input {
  width: 460px; max-width: 60vw;
  background: #0f1217;
  border: 1px solid #1d222b;
  color: var(--text);
  padding: 10px 12px; border-radius: 10px;
}
.control {
  background: #0f1217;
  border: 1px solid #1d222b;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.35;
}
.control:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(255,42,42,0.15);
}
select.control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23c1c6cf' d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px 6px;
  padding-right: 28px;
}
.topbar .user { display: flex; align-items: center; gap: 12px; }
/* Notifications icon removed */
.avatar { background: linear-gradient(135deg, #45506d, #2b344a); width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; }

.content { padding: 18px; overflow: auto; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid #23252a; border-radius: 14px; padding: 14px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.kpi .delta { margin-top: 6px; font-size: 12px; }
.kpi .delta.up { color: var(--accent); }
.kpi .delta.down { color: var(--danger); }

.panels { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; }
.panel { background: var(--panel); border: 1px solid #23252a; border-radius: 14px; padding: 14px; box-shadow: var(--shadow); width: 100%; max-width: 100%; min-width: 0; overflow: hidden; }
.panel h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.panel.full { grid-column: 1 / -1; }

/* Table responsiveness */
.table-responsive { width: 100%; overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid #242b3d; font-size: 14px; }
.table th { color: var(--muted); text-align: left; font-weight: 600; }
.badge { padding: 4px 8px; border-radius: 999px; font-size: 12px; border: 1px solid #2b3550; background: #151b28; }
.badge.ok { border-color: #164f3c; background: #0d2019; color: #62e0b8; }
.badge.warn { border-color: #553a15; background: #1f160a; color: #f3b567; }
.badge.info { border-color: #4a1212; background: #160909; color: #ff9b9b; }
.badge.danger { border-color: #6d1414; background: #200b0b; color: #ff6b6b; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Location tiles */
.loc-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.loc-card { background: var(--panel-2); border: 1px solid #23252a; border-radius: 12px; padding: 12px; min-height: 110px; box-shadow: var(--shadow); display: grid; align-content: space-between; min-width: 0; }
.loc-card .label { color: var(--muted); font-size: 12px; letter-spacing: 0.3px; }
.loc-card .count { font-size: 28px; line-height: 1; font-weight: 800; color: var(--text); }

/* Emails layout */
.email-layout { display: grid; grid-template-columns: 320px 1fr 360px; gap: 14px; height: calc(100vh - 64px - 36px); }
.email-list, .email-view, .email-compose { background: var(--panel); border: 1px solid #23252a; border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; }
.email-list .item { padding: 12px; border-bottom: 1px solid #232a3c; cursor: pointer; }
.email-list .item:hover { background: #191b1e; }
.email-list .item.active { background: #1b1414; border-left: 3px solid var(--brand); }
.email-view header { padding: 12px; border-bottom: 1px solid #232a3c; }
.email-view .body { padding: 12px; white-space: pre-wrap; overflow: auto; }
.email-compose textarea { flex: 1; background: transparent; color: var(--text); border: none; padding: 12px; resize: none; }
.email-compose footer { padding: 10px; border-top: 1px solid #232a3c; display: flex; justify-content: space-between; }

/* Chat layout */
.chat-layout { display: grid; grid-template-columns: 260px 1fr; gap: 14px; height: calc(100vh - 64px - 36px); }
.chat-rooms, .chat-room, .chat-compose { background: var(--panel); border: 1px solid #23252a; border-radius: 14px; }
.chat-rooms { overflow: auto; }
.chat-rooms .room { padding: 12px; border-bottom: 1px solid #232a3c; cursor: pointer; }
.chat-rooms .room.active { background: #1a2230; }
.chat-room { display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; }
.chat-room header { padding: 12px; border-bottom: 1px solid #232a3c; }
.chat-messages { padding: 12px; overflow: auto; display: grid; gap: 8px; }
.msg { max-width: 70%; padding: 10px 12px; border-radius: 12px; border: 1px solid #2a2a2f; background: #151618; }
.msg.me { justify-self: end; background: #1a1212; border-color: #4a1212; }
.chat-compose { display: flex; gap: 8px; align-items: center; padding: 10px; }
.chat-compose input { flex: 1; background: #111623; border: 1px solid #20283a; color: var(--text); padding: 10px 12px; border-radius: 10px; }
.btn { padding: 8px 12px; border-radius: 10px; border: 1px solid #2a2d36; background: #171a20; color: var(--text); cursor: pointer; }
.btn.primary { background: linear-gradient(135deg, #ff3b3b, #b82020); border-color: #8f1a1a; }
.btn.danger { background: linear-gradient(135deg, #b82020, #6f1515); border-color: #8f1a1a; }
.btn.ghost { background: transparent; }

/* Task detail layout */
.task-detail { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
.task-header { display: grid; gap: 10px; margin-bottom: 10px; }
.task-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-start; }
.title-input { font-size: 20px; font-weight: 700; }
.title-input.full { width: 100%; }
.task-section { display: grid; gap: 8px; }
.section-title { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }

/* Responsive */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .panels { grid-template-columns: minmax(0, 1fr); width: 100%; max-width: 100%; min-width: 0; }
  .email-layout { grid-template-columns: 1fr; height: auto; }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .task-detail { grid-template-columns: 1fr; }
}

/* Panel + page padding tweaks for small screens */
@media (max-width: 600px) {
  .content { padding: 12px; }
  .panel { padding: 12px; border-radius: 12px; }
}

/* Add safe bottom padding on mobile so content isn't hidden behind iOS bars */
@media (max-width: 900px) {
  .content { padding-bottom: calc(24px + var(--safe-bottom)); }
}

/* Settings/Profile */
.settings-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.profile-wrap { display: grid; grid-template-columns: 180px 1fr; gap: 16px; align-items: start; }
.avatar-preview { width: 160px; height: 160px; border-radius: 50%; border: 1px solid #2a2d36; object-fit: cover; box-shadow: var(--shadow); background: #121317; }
.avatar-preview.initials { display: grid; place-items: center; font-size: 48px; font-weight: 700; color: var(--text); }
.profile-left { display: grid; gap: 10px; align-content: start; }
.profile-left input[type="file"] { margin-top: 16px; }
.profile-form { display: grid; }
.profile-form label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* Auth/Login */
body.auth .sidebar { display: none; }
body.auth .topbar { display: none; }
body.auth .app { display: block; height: auto; min-height: 100vh; }
body.auth .main { display: block; }
body.auth .content { padding: 0; }
.auth-layout { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1000px 600px at -10% -20%, #171a22 0%, #0a0a0b 40%), var(--bg); width: 100%; margin: 0; }
.auth-card { width: 100%; max-width: 100%; background: var(--panel); border: 1px solid #23252a; border-radius: 16px; box-shadow: var(--shadow); padding: 24px; }
.auth-card .brand { display:flex; justify-content:center; padding-bottom: 8px; }
.auth-card h2 { margin: 8px 0; }
.auth-card p { margin: 0 0 16px; color: var(--muted); }
@media (max-width: 900px) {
  .auth-layout { width: 100%; margin: 0; padding: 16px; justify-items: center; }
}

/* Desktop: center auth card at 50% width */
@media (min-width: 900px) {
  .auth-layout { justify-items: center; }
  .auth-layout .auth-card { width: 50%; max-width: 50%; }
}

/* Mobile layout adjustments */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 1000; inset: 0 auto 0 0; width: min(80vw, 300px); transform: translateX(-100%); transition: transform 0.25s ease; }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-open .scrim { display: block; }
  .hamburger { display: inline-block; }
  .topbar { gap: 10px; height: 48px; min-height: 48px; padding: 8px 12px; }
  .topbar .search { display: none; }
  .brand-mobile { display: flex; }
  .topbar .brand-mobile img { height: 18px; max-height: 18px; width: auto; display: block; }
  /* Allow horizontal scrolling for wide tables */
  .table { min-width: 720px; }
  /* Two-up tiles on mobile and small tablets */
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi { padding: 10px; border-radius: 10px; height: var(--tile-mobile-h); min-height: var(--tile-mobile-h); }
  .kpi .label { font-size: 11px; }
  .kpi .value { font-size: 20px; }
  .kpi .delta { font-size: 11px; }
  .loc-cards { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px; align-items: stretch; width: 100%; }
  .loc-card { height: var(--tile-mobile-h); min-height: var(--tile-mobile-h); padding: 10px; border-radius: 10px; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; }
  .loc-card .label { font-size: 11px; }
  .loc-card .count { font-size: 20px; }
}

/* Small phones: force tiles to stack */
@media (max-width: 600px) {
  /* Two-up stacking for compact tiles */
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi { padding: 10px; border-radius: 10px; height: var(--tile-mobile-h); min-height: var(--tile-mobile-h); }
  .kpi .label { font-size: 11px; }
  .kpi .value { font-size: 20px; }
  .kpi .delta { font-size: 11px; }

  .loc-cards { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; grid-auto-rows: var(--tile-mobile-h); gap: 8px; align-items: stretch; width: 100%; }
  .loc-card { height: var(--tile-mobile-h); min-height: var(--tile-mobile-h); padding: 10px; border-radius: 10px; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; }
  .loc-card .label { font-size: 11px; }
  .loc-card .count { font-size: 20px; }
}
