@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

* { box-sizing: border-box; }
html { color-scheme: dark; }
html, body { height: 100%; margin: 0; background:#12181B; }
body.drawer-lock { overflow:hidden; }

.tri-app { --bg:#12181B; --panel:#1B2226; --panel2:#222A2F; --line:#2E373C;
  --text:#EDEDE6; --muted:#8B9296; --brass:#D9A441; --teal:#4C9A8B; --danger:#C1553F;
  font-family:'IBM Plex Sans', sans-serif; background:var(--bg); color:var(--text);
  height:100vh; height:100dvh; width:100%; overflow:hidden; display:flex; flex-direction:column; }
.tri-serif { font-family:'Fraunces', serif; }
.tri-app button { font-family:inherit; cursor:pointer; }
.tri-app input, .tri-app select, .tri-app textarea { font-family:inherit; }

/* ---- Login ---- */
.login-wrap { min-height:100%; height:auto; width:100%; display:flex; align-items:center; justify-content:center;
  position:relative; overflow:auto; padding:40px 20px; flex:1; }
.login-bg { position:absolute; inset:0; z-index:0; overflow:hidden; }
.login-bg::before { content:""; position:absolute; inset:-4%; z-index:0;
  background:
    linear-gradient(180deg, rgba(18,24,27,.78), rgba(18,24,27,.93) 55%, rgba(18,24,27,1) 100%),
    url('building-bg.jpg') center 30% / cover no-repeat;
  animation: loginKenburns 26s ease-in-out infinite alternate; }
.login-bg::after { content:""; position:absolute; inset:0; z-index:1; mix-blend-mode:screen; opacity:.5;
  background:linear-gradient(115deg, transparent 30%, rgba(217,164,65,.16) 45%, transparent 60%);
  background-size:220% 220%; animation: loginSheen 9s ease-in-out infinite; }
@keyframes loginKenburns { from { transform:scale(1) translate(0,0); } to { transform:scale(1.1) translate(-1.5%,-1%); } }
@keyframes loginSheen { 0% { background-position:120% -20%; } 50% { background-position:20% 60%; } 100% { background-position:-40% 120%; } }

.login-particles { position:absolute; inset:0; z-index:1; overflow:hidden; pointer-events:none; }
.particle { position:absolute; bottom:-4%; left:0; border-radius:50%; background:radial-gradient(circle,#F5D98A,var(--brass) 70%);
  box-shadow:0 0 8px 1px rgba(217,164,65,.75); opacity:0; animation-name:loginFloat; animation-timing-function:linear;
  animation-iteration-count:infinite; }
@keyframes loginFloat {
  0% { transform:translate(0,0); opacity:0; }
  10% { opacity:.85; }
  85% { opacity:.5; }
  100% { transform:translate(var(--drift,20px), -112vh); opacity:0; }
}

.login-content { position:relative; z-index:2; display:flex; flex-direction:column; align-items:center;
  gap:34px; width:100%; max-width:520px; animation:loginRise .9s cubic-bezier(.22,.8,.32,1) both; }
@keyframes loginRise { from { opacity:0; transform:translateY(22px); } to { opacity:1; transform:translateY(0); } }

.towers { display:flex; align-items:flex-end; gap:14px; height:170px; }
.tower { background:linear-gradient(180deg,#232C31,#171D20); border:1px solid var(--line);
  border-radius:6px 6px 0 0; position:relative; display:grid; grid-template-columns:repeat(3,1fr);
  gap:5px; padding:8px; align-content:start; box-shadow:0 10px 30px rgba(0,0,0,.35); }
.win { width:8px; height:8px; border-radius:1px; background:#2E373C; }
.win.lit { background:var(--brass); box-shadow:0 0 6px rgba(217,164,65,.7); animation-name:loginTwinkle;
  animation-timing-function:ease-in-out; animation-iteration-count:infinite; }
@keyframes loginTwinkle { 0%,100% { opacity:1; } 50% { opacity:.35; box-shadow:0 0 2px rgba(217,164,65,.35); } }

.login-heading { display:flex; flex-direction:column; align-items:center; gap:16px; text-align:center; }
.login-title { font-family:'Fraunces', serif; font-optical-sizing:auto; font-size:clamp(2.1rem, 6vw, 3.25rem);
  font-weight:600; line-height:1.18; letter-spacing:.2px; margin:0;
  background:linear-gradient(180deg, #F7EBCB 10%, #E7B95B 55%, #B8802F 95%);
  -webkit-background-clip:text; background-clip:text; color:transparent;
  filter:drop-shadow(0 2px 18px rgba(217,164,65,.28)); }
.login-divider { width:56px; height:2px; border-radius:2px; background:linear-gradient(90deg,transparent,var(--brass),transparent); }
.login-sub { color:var(--muted); text-align:center; max-width:420px; line-height:1.6; font-size:.95rem; margin:0; }

.role-row { display:flex; gap:16px; flex-wrap:wrap; justify-content:center; }
.role-card { background:var(--panel); border:1px solid var(--line); border-radius:10px;
  padding:20px 22px; width:190px; text-align:left; transition:border-color .15s; }
.role-card:hover { border-color:var(--brass); }
.role-card.active { border-color:var(--brass); background:var(--panel2); }
.role-card h4 { margin:10px 0 4px; font-size:1.02rem; }
.role-card p { margin:0; color:var(--muted); font-size:.82rem; }
.login-form { display:flex; flex-direction:column; gap:11px; width:290px; max-width:100%; }
.login-form input { background:rgba(27,34,38,.75); backdrop-filter:blur(6px); border:1px solid var(--line);
  border-radius:8px; padding:12px 14px; color:var(--text); width:100%; transition:border-color .15s, background .15s; }
.login-form input:focus { outline:none; border-color:var(--brass); background:rgba(27,34,38,.95); }
.login-form .btn { justify-content:center; padding:11px 16px; }
.btn { background:var(--panel2); border:1px solid var(--line); color:var(--text);
  border-radius:6px; padding:9px 16px; font-size:.86rem; display:inline-flex; align-items:center; gap:6px; }
.btn:hover { border-color:var(--brass); }
.btn-brass { background:var(--brass); color:#1B140A; border-color:var(--brass); font-weight:600; }
.btn-brass:hover { filter:brightness(1.06); }
.btn-teal { background:var(--teal); color:#0A1614; border-color:var(--teal); font-weight:600; }
.btn-danger { background:var(--danger); color:#2A0C06; border-color:var(--danger); font-weight:600; }
.btn-ghost { background:transparent; }
.btn-sm { padding:6px 10px; font-size:.78rem; }
.btn:disabled { opacity:.6; cursor:default; }

/* ---- Shell ---- */
.shell { display:flex; height:100%; width:100%; }
.sidebar { width:222px; background:var(--panel); border-right:1px solid var(--line);
  display:flex; flex-direction:column; flex-shrink:0; }
.brand { display:flex; align-items:center; gap:10px; padding:20px 18px; border-bottom:1px solid var(--line); }
.brand-name { font-size:1.05rem; font-weight:600; line-height:1.1; }
.brand-sub { color:var(--muted); font-size:.68rem; letter-spacing:.03em; }
.nav { flex:1; padding:14px 10px; display:flex; flex-direction:column; gap:2px; overflow-y:auto; }
.nav-item { display:flex; align-items:center; gap:10px; padding:10px 12px; border-radius:7px;
  color:var(--muted); background:transparent; border:none; text-align:left; font-size:.87rem; width:100%; }
.nav-item:hover { color:var(--text); background:var(--panel2); }
.nav-item.active { color:#1B140A; background:var(--brass); font-weight:600; }
.sidebar-foot { padding:14px 10px; border-top:1px solid var(--line); }
.main { flex:1; display:flex; flex-direction:column; overflow:hidden; min-width:0; }
.topbar { display:flex; align-items:center; justify-content:space-between; padding:16px 26px;
  border-bottom:1px solid var(--line); flex-shrink:0; }
.topbar h2 { margin:0; font-size:1.25rem; font-weight:600; }
.topbar .meta { color:var(--muted); font-size:.8rem; margin-top:2px; }
.badge-role { background:var(--panel2); border:1px solid var(--line); border-radius:20px;
  padding:5px 14px; font-size:.78rem; color:var(--brass); }
.content { flex:1; overflow-y:auto; padding:22px 26px 60px; }

/* ---- Cards / grids ---- */
.grid { display:grid; gap:16px; }
.grid-4 { grid-template-columns:repeat(4,1fr); }
.grid-3 { grid-template-columns:repeat(3,1fr); }
.grid-2 { grid-template-columns:repeat(2,1fr); }
@media (max-width:1000px){ .grid-4{grid-template-columns:repeat(2,1fr);} .grid-3{grid-template-columns:repeat(2,1fr);} .grid-2{grid-template-columns:1fr;} }
.card { background:var(--panel); border:1px solid var(--line); border-radius:10px; padding:18px; }
.kpi-label { color:var(--muted); font-size:.78rem; margin-bottom:8px; }
.kpi-num { font-size:1.9rem; font-weight:600; }
.kpi-sub { color:var(--muted); font-size:.75rem; margin-top:4px; }
.section-title { font-size:.95rem; font-weight:600; margin:26px 0 12px; color:var(--text); }
.section-title:first-child { margin-top:0; }

/* ---- Table ---- */
table { width:100%; border-collapse:collapse; font-size:.85rem; }
th { text-align:left; color:var(--muted); font-weight:500; font-size:.74rem; text-transform:uppercase;
  letter-spacing:.04em; padding:8px 10px; border-bottom:1px solid var(--line); }
td { padding:10px; border-bottom:1px solid var(--line); }
tr:last-child td { border-bottom:none; }
.tag { display:inline-block; padding:3px 10px; border-radius:20px; font-size:.72rem; font-weight:600; }
.tag-green { background:rgba(76,154,139,.18); color:#7FCBBA; }
.tag-amber { background:rgba(217,164,65,.18); color:var(--brass); }
.tag-red { background:rgba(193,85,63,.18); color:#E28C79; }
.tag-grey { background:var(--panel2); color:var(--muted); }
select.inline, input.inline { background:var(--bg); border:1px solid var(--line); color:var(--text);
  border-radius:5px; padding:5px 8px; font-size:.8rem; }

/* ---- Forms ---- */
.form-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:14px; }
.form-grid.full { grid-template-columns:1fr; }
.field label { display:block; font-size:.76rem; color:var(--muted); margin-bottom:5px; }
.field input, .field select, .field textarea { width:100%; background:var(--bg); border:1px solid var(--line);
  color:var(--text); border-radius:6px; padding:9px 11px; font-size:.85rem; }
.field textarea { resize:vertical; min-height:64px; }

/* ---- misc ---- */
.bill-row { display:flex; justify-content:space-between; padding:7px 0; font-size:.88rem; color:var(--muted); }
.bill-row.total { color:var(--text); font-weight:600; border-top:1px solid var(--line); margin-top:6px; padding-top:12px; font-size:1rem; }
.progress-track { background:var(--panel2); border-radius:20px; height:8px; overflow:hidden; margin-top:8px; }
.progress-fill { background:var(--brass); height:100%; }
.notice-card { border-left:3px solid var(--line); padding:12px 16px; margin-bottom:10px; background:var(--panel2); border-radius:0 8px 8px 0; }
.notice-card.pinned { border-left-color:var(--brass); }
.toast { position:fixed; top:18px; right:18px; background:var(--panel2); border:1px solid var(--brass);
  color:var(--text); padding:12px 18px; border-radius:8px; font-size:.85rem; z-index:50;
  font-family:'IBM Plex Sans', sans-serif; opacity:0; pointer-events:none; transform:translateY(-8px);
  transition:opacity .2s, transform .2s; }
.toast.show { opacity:1; transform:translateY(0); }
.empty { color:var(--muted); font-size:.85rem; padding:20px 0; text-align:center; }
.expense-thumb { width:40px; height:40px; object-fit:cover; border-radius:6px; border:1px solid var(--line); display:block; }
.sos-btn { width:100%; background:var(--danger); color:#fff; border:none; border-radius:12px;
  padding:26px; font-size:1.1rem; font-weight:700; display:flex; align-items:center; justify-content:center; gap:10px; }

/* ---- simple bar chart (replaces recharts) ---- */
.barchart { display:flex; align-items:flex-end; gap:18px; height:100%; padding:6px 4px 0; }
.barchart-col { flex:1; display:flex; flex-direction:column; align-items:center; justify-content:flex-end; height:100%; }
.barchart-val { font-size:.72rem; color:var(--muted); margin-bottom:6px; }
.barchart-bar { width:60%; border-radius:4px 4px 0 0; min-height:2px; transition:height .3s; }
.barchart-label { font-size:.72rem; color:var(--muted); margin-top:8px; }

svg.icon { flex-shrink:0; vertical-align:middle; }

/* ---- Hamburger button (mobile top bar) ---- */
.hamburger-btn { display:none; background:transparent; border:none; color:var(--text);
  padding:9px; margin:-9px 2px -9px -6px; border-radius:12px; align-items:center; justify-content:center;
  transition:background .15s, transform .1s; flex-shrink:0; }
.hamburger-btn:active { background:var(--panel2); transform:scale(.92); }

/* ---- Nav drawer (Android-style) ---- */
.drawer-overlay { display:none; position:fixed; inset:0; background:rgba(6,9,10,.55); backdrop-filter:blur(2px);
  -webkit-backdrop-filter:blur(2px); z-index:80; opacity:0; pointer-events:none; transition:opacity .25s ease; }
.drawer-overlay.show { opacity:1; pointer-events:auto; }
.drawer { display:flex; position:fixed; top:0; left:0; bottom:0; width:286px; max-width:84vw; z-index:90;
  background:linear-gradient(180deg,#1D2529,#151B1E 60%); border-right:1px solid var(--line);
  flex-direction:column; transform:translateX(-105%);
  transition:transform .3s cubic-bezier(.32,.72,0,1); box-shadow:14px 0 40px rgba(0,0,0,.45); }
.drawer.open { transform:translateX(0); }
.drawer-header { display:flex; align-items:center; gap:10px; padding:22px 18px 16px; position:relative; }
.drawer-header .brand-name { font-size:1.08rem; }
.drawer-close { position:absolute; top:14px; right:12px; background:transparent; border:none;
  color:var(--muted); padding:8px; border-radius:10px; }
.drawer-close:active { background:var(--panel2); }
.drawer-user { display:flex; align-items:center; gap:12px; margin:2px 18px 14px; padding:14px;
  background:var(--panel2); border:1px solid var(--line); border-radius:14px; }
.drawer-avatar { width:40px; height:40px; border-radius:50%; flex-shrink:0; display:flex; align-items:center;
  justify-content:center; font-weight:700; font-size:1.05rem; color:#1B140A;
  background:linear-gradient(145deg,var(--brass),#B8802F); }
.drawer-user-name { font-size:.92rem; font-weight:600; line-height:1.25; }
.drawer-user-role { font-size:.74rem; color:var(--muted); }
.drawer-nav { flex:1; overflow-y:auto; padding:6px 12px; display:flex; flex-direction:column; gap:3px; }
.drawer-item { display:flex; align-items:center; gap:14px; padding:13px 14px; border-radius:12px;
  border:none; background:transparent; color:var(--muted); font-size:.9rem; width:100%; text-align:left;
  transition:background .15s, color .15s, transform .1s; }
.drawer-item:active { transform:scale(.98); }
.drawer-item.active { background:linear-gradient(90deg,rgba(217,164,65,.16),rgba(217,164,65,.04));
  color:var(--brass); font-weight:600; box-shadow:inset 3px 0 0 var(--brass); }
.drawer-foot { padding:14px 18px calc(16px + env(safe-area-inset-bottom)); border-top:1px solid var(--line); }
.drawer-foot .btn { width:100%; justify-content:center; }

/* ---- Bottom nav (Android-style) ---- */
.bottomnav { display:none; }

/* ---- Mobile & tablet (drawer + bottom nav shell) ----
   Only switches to the hamburger/drawer layout on real touch devices (phones/tablets),
   never on a desktop/laptop just because its browser window happens to be narrow. */
@media (max-width: 900px) and (pointer: coarse) {
  .tri-app { height:auto; min-height:100vh; min-height:100dvh; overflow:visible; }
  .shell { flex-direction:column; height:auto; min-height:100vh; min-height:100dvh; }
  .sidebar { display:none; }
  .hamburger-btn { display:inline-flex; }
  .drawer-overlay { display:block; }
  .main { overflow:visible; }
  .content { overflow:visible; padding:14px 14px calc(94px + env(safe-area-inset-bottom)); }
  .topbar { padding:13px 16px; flex-wrap:wrap; gap:8px; position:sticky; top:0; z-index:30;
    background:rgba(18,24,27,.92); backdrop-filter:blur(10px); -webkit-backdrop-filter:blur(10px);
    box-shadow:0 2px 14px rgba(0,0,0,.28); }
  .topbar h2 { font-size:1.08rem; }
  .topbar .meta { font-size:.72rem; }
  .badge-role { padding:4px 11px; font-size:.72rem; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns:repeat(2,1fr); }
  .card { padding:15px; border-radius:16px; overflow-x:auto;
    box-shadow:0 3px 14px rgba(0,0,0,.22); }
  .kpi-num { font-size:1.6rem; }
  table { min-width:480px; }
  .form-grid { grid-template-columns:1fr 1fr; }
  .login-content { gap:24px; }
  .towers { height:130px; gap:10px; }
  .login-title { font-size:clamp(1.7rem, 8vw, 2.4rem); }
  .login-form { width:100%; max-width:320px; }
  .role-card { width:100%; }
  .btn { padding:11px 16px; border-radius:10px; }
  .btn:active { transform:scale(.97); }
  .btn-sm { padding:8px 12px; }

  .bottomnav { display:flex; position:fixed; left:0; right:0; bottom:0; z-index:70;
    background:rgba(27,34,38,.96); backdrop-filter:blur(14px); -webkit-backdrop-filter:blur(14px);
    border-top:1px solid var(--line); padding:8px 6px calc(8px + env(safe-area-inset-bottom));
    box-shadow:0 -6px 24px rgba(0,0,0,.4); }
  .bottomnav-item { flex:1; display:flex; flex-direction:column; align-items:center; gap:3px;
    padding:5px 2px; border:none; background:transparent; color:var(--muted); font-size:.63rem;
    font-weight:500; border-radius:14px; transition:color .15s; }
  .bottomnav-item:active { transform:scale(.94); }
  .bnav-icon-wrap { padding:5px 16px; border-radius:14px; transition:background .2s, color .2s; }
  .bottomnav-item.active { color:var(--brass); }
  .bottomnav-item.active .bnav-icon-wrap { background:rgba(217,164,65,.16); }
}

/* ---- Narrow phones (grid collapses to single column, tighter spacing) ---- */
@media (max-width: 620px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns:1fr; }
  .form-grid { grid-template-columns:1fr; }
}

/* ---- Very small phones (iPhone SE / older Android, <=380px) ---- */
@media (max-width: 380px) {
  .login-content { gap:18px; }
  .towers { height:96px; gap:7px; }
  .tower { padding:6px; gap:4px; }
  .win { width:6px; height:6px; }
  .login-title { font-size:clamp(1.5rem, 9vw, 2rem); }
  .login-sub { font-size:.85rem; }
  .topbar h2 { font-size:1rem; }
  .kpi-num { font-size:1.4rem; }
  .card { padding:12px; }
  .content { padding:10px 10px calc(90px + env(safe-area-inset-bottom)); }
  .bottomnav-item { font-size:.6rem; }
  .bnav-icon-wrap { padding:5px 12px; }
}

/* ---- Short / landscape phones (address bar eats vertical space) ---- */
@media (max-width: 900px) and (max-height: 480px) {
  .login-wrap { padding:20px 20px; }
  .login-content { gap:14px; }
  .towers { display:none; }
  .login-title { font-size:1.6rem; }
  .login-sub { display:none; }
}

/* ---- Tablets in landscape / small laptops: keep sidebar, tighten grid ---- */
@media (min-width: 901px) and (max-width: 1100px) {
  .sidebar { width:190px; }
  .grid-4 { grid-template-columns:repeat(3,1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .login-bg::before, .login-bg::after, .particle, .win.lit, .login-content { animation:none !important; }
}
