@import url('fonts.css');

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design tokens (dark mode defaults) ── */
:root {
  --bg: #0f1117; --surface: #1a1d27; --surface2: #21253a; --border: #2a2d3a;
  --accent: #3b82f6; --accent-dim: rgba(59,130,246,0.12);
  --text: #f1f5f9; --muted: #64748b;
  --green: #34d399; --yellow: #fbbf24; --red: #f87171;
  --green-bg: rgba(52,211,153,0.12);
  --yellow-bg: rgba(251,191,36,0.12);
  --red-bg: rgba(248,113,113,0.12);
  --error: #f87171;
}

body {
  background: var(--bg); color: var(--text);
  font-family: 'DM Sans', sans-serif; min-height: 100vh; display: flex;
}

/* ── Top Nav ── */
.top-nav {
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 56px; position: sticky; top: 0; z-index: 200;
  flex-shrink: 0;
}
.nav-brand { display: flex; align-items: center; }
.nav-brand-link { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.nav-logo { height: 32px; width: auto; display: block; border-radius: 8px; }
.nav-brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; color: var(--text); }
.nav-brand-accent { color: #F7931E; margin-left: 4px; }
.nav-right { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.nav-user { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 28px; height: 28px; background: var(--accent-dim); border: 1px solid var(--accent);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: var(--accent);
}
.role-badge {
  font-family: 'DM Mono', monospace; font-size: 10px; padding: 2px 7px; border-radius: 10px;
}
.badge-super { background: rgba(251,191,36,0.15); color: #fbbf24; border: 1px solid rgba(251,191,36,0.3); }
.badge-admin { background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(59,130,246,0.2); }
.badge-member { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }
.nav-admin-link {
  color: var(--muted); text-decoration: none; font-size: 12px;
  font-family: 'DM Mono', monospace; padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 5px; transition: all 0.15s;
}
.nav-admin-link:hover, .nav-admin-link.active { border-color: var(--accent); color: var(--accent); }
a.logout {
  color: var(--muted); text-decoration: none; font-size: 12px;
  font-family: 'DM Mono', monospace; padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 5px; transition: all 0.15s;
}
a.logout:hover { border-color: var(--muted); color: var(--text); }

/* ── Layout ── */
.app-layout { display: flex; min-height: calc(100vh - 56px); }
body.app { flex-direction: column; }

/* ── Sidebar ── */
.sidebar {
  width: 220px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 12px 0; flex-shrink: 0; overflow-y: auto;
  display: flex; flex-direction: column;
}
.sidebar-section { padding: 0 12px; margin-bottom: 4px; }
.sidebar-tools { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.sidebar-label {
  font-size: 10px; font-family: 'DM Mono', monospace; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted); padding: 6px 8px 3px;
}
.sidebar-tenant {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 8px; border-radius: 6px; text-decoration: none;
  color: var(--text); font-size: 14px; transition: background 0.12s;
}
.sidebar-tenant:hover { background: var(--surface2); }
.sidebar-tenant.active { background: var(--accent-dim); color: var(--accent); }
.tenant-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-badge {
  font-size: 10px; font-family: 'DM Mono', monospace;
  background: var(--border); padding: 1px 6px; border-radius: 10px; color: var(--muted); margin-left: 6px;
}
.sidebar-tool {
  display: block; padding: 7px 8px; border-radius: 6px;
  text-decoration: none; color: var(--muted); font-size: 14px; transition: all 0.12s;
}
.sidebar-tool:hover { background: var(--surface2); color: var(--text); }
.sidebar-tool.active { background: var(--accent-dim); color: var(--accent); font-weight: 500; }
.sidebar-add-btn {
  width: 100%; background: none; border: none; text-align: left;
  padding: 7px 8px; border-radius: 6px; color: var(--accent); font-size: 14px;
  cursor: pointer; font-family: 'DM Sans', sans-serif; transition: background 0.12s;
}
.sidebar-add-btn:hover { background: var(--accent-dim); }

/* ── Main Content ── */
.main-content { flex: 1; overflow: auto; }

/* ── Shared Modal ── */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px); z-index: 1000; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 28px; width: 100%; max-width: 440px; margin: 0 20px;
}
.modal-lg { max-width: 580px; }
.modal-title { font-size: 17px; font-weight: 600; margin-bottom: 20px; }
.field { margin-bottom: 14px; }
label {
  display: block; font-size: 11px; font-family: 'DM Mono', monospace;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 5px;
}
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-family: 'DM Sans', sans-serif;
  font-size: 14px; padding: 9px 12px; outline: none; transition: border-color 0.15s;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select option { background: var(--surface); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 6px; padding: 7px 14px; font-family: 'DM Sans', sans-serif;
  font-size: 14px; font-weight: 500; cursor: pointer; border: none; transition: background 0.15s;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: #2563eb; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface2); border-color: var(--muted); }
.btn-danger { background: rgba(248,113,113,0.15); color: var(--red); border: 1px solid rgba(248,113,113,0.3); }
.btn-danger:hover { background: rgba(248,113,113,0.25); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 5px 8px; }

/* ── Page header ── */
.page-wrap { padding: 28px 32px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.page-title { font-size: 21px; font-weight: 600; letter-spacing: -0.3px; }
.page-sub { color: var(--muted); font-size: 14px; margin-top: 3px; }
.page-actions { display: flex; gap: 8px; }

/* ── Table ── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; font-size: 11px; font-family: 'DM Mono', monospace;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface); font-weight: 500;
}
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:nth-child(even) td { background: var(--surface2); }
.data-table tr:hover td { background: var(--surface2); }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state .empty-icon { font-size: 36px; opacity: 0.4; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── Status badges ── */
.badge {
  display: inline-block; font-size: 11px; font-family: 'DM Mono', monospace;
  padding: 2px 8px; border-radius: 10px; font-weight: 500;
}
.badge-green  { background: rgba(52,211,153,0.15); color: var(--green); border: 1px solid rgba(52,211,153,0.3); }
.badge-yellow { background: rgba(251,191,36,0.15); color: var(--yellow); border: 1px solid rgba(251,191,36,0.3); }
.badge-red    { background: rgba(248,113,113,0.15); color: var(--red); border: 1px solid rgba(248,113,113,0.3); }
.badge-muted  { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }
.badge-blue   { background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(59,130,246,0.2); }

/* ── Action buttons ── */
.action-btns { display: flex; gap: 6px; flex-wrap: nowrap; }

/* ── Theme toggle ── */
.theme-toggle {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 5px; padding: 4px 8px; cursor: pointer; font-size: 14px;
  transition: all 0.15s; line-height: 1; font-family: inherit;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ── Hamburger button (hidden on desktop) ── */
.hamburger {
  display: none;
  flex-direction: column; justify-content: center; align-items: center;
  gap: 5px; width: 36px; height: 36px; background: none; border: none;
  cursor: pointer; padding: 4px; border-radius: 6px; margin-right: 8px;
}
.hamburger span {
  display: block; width: 20px; height: 2px;
  background: var(--text); border-radius: 2px; transition: all 0.2s;
}
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Mobile nav overlay ── */
.nav-overlay {
  display: none; position: fixed; inset: 56px 0 0 0;
  background: rgba(0,0,0,0.5); z-index: 299;
}
.nav-overlay.open { display: block; }

/* ── Sidebar mobile footer (hidden on desktop) ── */
.sidebar-mobile-footer { display: none; }

/* ── Mobile responsive ── */
@media (max-width: 900px) {
  .hamburger { display: flex; }
  .nav-hide-mobile { display: none !important; }
  .nav-user-name { display: none; }
  .nav-role-badge { display: none; }

  .sidebar {
    position: fixed; top: 56px; left: 0; height: calc(100vh - 56px);
    z-index: 300; transform: translateX(-100%);
    transition: transform 0.25s ease; box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }

  .sidebar-mobile-footer {
    display: block; margin-top: auto; padding: 12px 0;
    border-top: 1px solid var(--border);
  }

  .app-layout { flex-direction: column; }
  .main-content { width: 100%; min-width: 0; }
}

/* ── Light theme overrides ── */
html[data-theme="light"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface2: #f1f5f9;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-dim: rgba(37,99,235,0.08);
  --text: #1e293b;
  --muted: #64748b;
  --green: #059669;
  --green-bg: rgba(5,150,105,0.08);
  --yellow: #d97706;
  --yellow-bg: rgba(217,119,6,0.08);
  --red: #dc2626;
  --red-bg: rgba(220,38,38,0.08);
  --error: #dc2626;
}
