/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'DM Sans', sans-serif;
  background: #0f1117;
  color: #e8e6df;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== CSS VARIABLES ===== */
:root {
  --bg: #0f1117;
  --bg2: #161922;
  --bg3: #1e2230;
  --surface: #232837;
  --surface2: #2a3145;
  --border: rgba(255,255,255,0.08);
  --border2: rgba(255,255,255,0.14);
  --text: #e8e6df;
  --text2: #9a97a0;
  --text3: #5c5a66;
  --accent: #4f8ef7;
  --accent2: #3a78e8;
  --green: #3ecf8e;
  --amber: #f5a623;
  --red: #f26b5b;
  --radius: 12px;
  --radius-sm: 8px;
  --nav-h: 64px;
  --top-h: 56px;
}

/* ===== SPLASH ===== */
#splash {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  z-index: 1000;
  animation: splashOut 0.4s ease 1.6s forwards;
}
@keyframes splashOut { to { opacity: 0; pointer-events: none; transform: scale(1.04); } }
.splash-logo { display: flex; align-items: center; gap: 12px; animation: fadeUp 0.5s ease 0.2s both; }
.splash-sub { color: var(--text2); font-size: 13px; letter-spacing: 0.04em; animation: fadeUp 0.5s ease 0.5s both; }

/* ===== LOGO MARK ===== */
.logo-mark {
  width: 44px; height: 44px;
  background: var(--accent);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'DM Mono', monospace;
  font-weight: 500;
  font-size: 20px;
  color: #fff;
  letter-spacing: -1px;
  flex-shrink: 0;
}
.logo-mark.sm { width: 34px; height: 34px; font-size: 15px; border-radius: 9px; }
.logo-mark.xs { width: 28px; height: 28px; font-size: 12px; border-radius: 7px; }
.logo-text { font-size: 22px; font-weight: 500; letter-spacing: -0.03em; color: var(--text); }

/* ===== SCREENS ===== */
.screen { position: fixed; inset: 0; overflow: hidden; }
.hidden { display: none !important; }

/* ===== AUTH ===== */
#screen-auth {
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.auth-wrap {
  width: 100%; max-width: 400px;
  display: flex; flex-direction: column;
  align-items: center; gap: 24px;
}
.auth-brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.auth-brand h1 { font-size: 24px; font-weight: 500; letter-spacing: -0.03em; }
.auth-brand p { color: var(--text2); font-size: 14px; }
.auth-card {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 28px 24px;
}
.auth-card h2 { font-size: 18px; font-weight: 500; margin-bottom: 20px; letter-spacing: -0.02em; }
.auth-switch { text-align: center; font-size: 13px; color: var(--text2); margin-top: 16px; }
.auth-switch a { color: var(--accent); cursor: pointer; }
.auth-footer { font-size: 11px; color: var(--text3); font-family: 'DM Mono', monospace; letter-spacing: 0.04em; }
.error-msg { background: rgba(242,107,91,0.1); border: 1px solid rgba(242,107,91,0.3); color: var(--red); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; margin-bottom: 14px; }

/* ===== TOPBAR ===== */
.topbar {
  height: var(--top-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  position: relative;
  z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-title { font-size: 15px; font-weight: 500; letter-spacing: -0.01em; }
.topbar-right { display: flex; align-items: center; gap: 4px; }

/* ===== MAIN ===== */
#main-content {
  position: absolute;
  top: var(--top-h);
  bottom: var(--nav-h);
  left: 0; right: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ===== PAGES ===== */
.page { padding: 16px 16px 24px; min-height: 100%; }
.page-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px;
}
.page-header h2 { font-size: 20px; font-weight: 500; letter-spacing: -0.03em; flex: 1; }
.page-header .sub { font-size: 13px; color: var(--text2); margin-top: 2px; }
.back-btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); width: 36px; height: 36px;
  border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ===== STATS ===== */
.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.stat-card:active { background: var(--surface2); }
.stat-card.warn { border-color: rgba(245,166,35,0.25); background: rgba(245,166,35,0.06); }
.stat-card.success { border-color: rgba(62,207,142,0.2); background: rgba(62,207,142,0.05); }
.stat-card.info { border-color: rgba(79,142,247,0.2); background: rgba(79,142,247,0.05); }
.stat-num {
  display: block;
  font-family: 'DM Mono', monospace;
  font-size: 28px; font-weight: 500;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1;
}
.stat-card.warn .stat-num { color: var(--amber); }
.stat-card.success .stat-num { color: var(--green); }
.stat-card.info .stat-num { color: var(--accent); }
.stat-label { display: block; font-size: 12px; color: var(--text2); margin-top: 6px; }

/* ===== SECTION HEADER ===== */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.section-header h3 { font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text2); }
.section-header a { font-size: 13px; color: var(--accent); cursor: pointer; }

/* ===== ASSET LIST ===== */
.asset-list { display: flex; flex-direction: column; gap: 8px; }
.asset-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex; align-items: flex-start; gap: 12px;
  animation: fadeUp 0.2s ease both;
}
.asset-card:active { background: var(--surface); border-color: var(--border2); }
.asset-type-icon {
  width: 38px; height: 38px;
  background: var(--surface);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.asset-info { flex: 1; min-width: 0; }
.asset-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-meta { font-size: 12px; color: var(--text2); margin-top: 3px; }
.asset-badges { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.badge {
  font-size: 11px; font-family: 'DM Mono', monospace;
  padding: 2px 8px; border-radius: 20px;
  border: 1px solid transparent;
}
.badge-type { background: rgba(79,142,247,0.1); border-color: rgba(79,142,247,0.2); color: #7aaff9; }
.badge-status-green { background: rgba(62,207,142,0.1); border-color: rgba(62,207,142,0.2); color: var(--green); }
.badge-status-amber { background: rgba(245,166,35,0.1); border-color: rgba(245,166,35,0.2); color: var(--amber); }
.badge-status-red { background: rgba(242,107,91,0.1); border-color: rgba(242,107,91,0.2); color: var(--red); }
.badge-status-gray { background: var(--surface); border-color: var(--border2); color: var(--text2); }
.badge-warranty-warn { background: rgba(245,166,35,0.1); border-color: rgba(245,166,35,0.25); color: var(--amber); }
.badge-warranty-ok { background: rgba(62,207,142,0.08); border-color: rgba(62,207,142,0.15); color: var(--green); }
.badge-warranty-exp { background: rgba(242,107,91,0.1); border-color: rgba(242,107,91,0.2); color: var(--red); }

/* ===== SEARCH & FILTER ===== */
.search-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 0 14px; margin-bottom: 12px;
  color: var(--text2);
}
.search-bar input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-size: 14px; padding: 11px 0;
  font-family: 'DM Sans', sans-serif;
}
.search-bar input::placeholder { color: var(--text3); }
.filter-row {
  display: flex; gap: 8px; overflow-x: auto;
  padding-bottom: 4px; margin-bottom: 14px;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); border-radius: 20px;
  padding: 6px 14px; font-size: 13px;
  cursor: pointer; white-space: nowrap;
  font-family: 'DM Sans', sans-serif;
  transition: all 0.15s;
}
.filter-btn.active {
  background: rgba(79,142,247,0.12);
  border-color: rgba(79,142,247,0.4);
  color: var(--accent);
}

/* ===== FORMS ===== */
.form-section {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  margin-bottom: 12px;
}
.form-section-title {
  font-size: 11px; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text3);
  margin-bottom: 16px;
}
.field-group { margin-bottom: 14px; }
.field-group:last-child { margin-bottom: 0; }
.field-group label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 6px; }
.req { color: var(--accent); }
.field-group input,
.field-group select,
.field-group textarea {
  width: 100%;
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px;
  padding: 10px 12px;
  font-family: 'DM Sans', sans-serif;
  outline: none; transition: border-color 0.15s;
  -webkit-appearance: none;
}
.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus { border-color: var(--accent); }
.field-group input::placeholder,
.field-group textarea::placeholder { color: var(--text3); }
.field-group select option { background: var(--bg3); color: var(--text); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; padding-bottom: 8px; }

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius-sm);
  padding: 12px 20px; font-size: 14px; font-weight: 500;
  cursor: pointer; font-family: 'DM Sans', sans-serif;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: background 0.15s, transform 0.1s;
  width: 100%;
}
.btn-primary:active { background: var(--accent2); transform: scale(0.98); }
.btn-secondary {
  background: var(--surface); color: var(--text2);
  border: 1px solid var(--border2); border-radius: var(--radius-sm);
  padding: 12px 20px; font-size: 14px; font-weight: 500;
  cursor: pointer; font-family: 'DM Sans', sans-serif;
  transition: background 0.15s;
  flex: 1;
}
.btn-secondary:active { background: var(--surface2); }
.btn-primary { flex: 2; }
.btn-fab {
  width: 38px; height: 38px; flex-shrink: 0;
  background: var(--accent); color: #fff;
  border: none; border-radius: 10px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.btn-fab:active { background: var(--accent2); transform: scale(0.94); }
.icon-btn {
  width: 36px; height: 36px;
  background: transparent; border: none;
  color: var(--text2); border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn.danger:hover { color: var(--red); }
.badge-dot {
  position: absolute; top: 6px; right: 6px;
  width: 7px; height: 7px;
  background: var(--red); border-radius: 50%;
  border: 1.5px solid var(--bg2);
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex; align-items: stretch;
  padding: 0 4px;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1; background: transparent; border: none;
  color: var(--text3);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px; cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: 10px;
  border-radius: 10px;
  transition: color 0.15s, background 0.15s;
}
.nav-item.active { color: var(--accent); }
.nav-item:active { background: var(--surface); }

/* ===== ASSET DETAIL ===== */
.detail-header-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  margin-bottom: 12px;
}
.detail-type-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.detail-type-icon { font-size: 36px; }
.detail-name { font-size: 18px; font-weight: 500; letter-spacing: -0.02em; }
.detail-client { font-size: 13px; color: var(--text2); margin-top: 3px; }
.detail-section {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
  margin-bottom: 12px;
}
.detail-section-title {
  font-size: 11px; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text3); margin-bottom: 14px;
}
.detail-row {
  display: flex; justify-content: space-between;
  align-items: flex-start; padding: 7px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { font-size: 13px; color: var(--text2); flex-shrink: 0; }
.detail-value { font-size: 13px; text-align: right; word-break: break-all; }
.detail-value.mono { font-family: 'DM Mono', monospace; font-size: 12px; }
.detail-value.accent { color: var(--accent); }
.detail-value.amber { color: var(--amber); }
.detail-value.red { color: var(--red); }
.detail-value.green { color: var(--green); }

/* ===== CLIENTS ===== */
.client-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  cursor: pointer; transition: border-color 0.15s;
  display: flex; align-items: center; gap: 14px;
  animation: fadeUp 0.2s ease both;
}
.client-card:active { border-color: var(--border2); }
.client-avatar {
  width: 42px; height: 42px;
  background: var(--surface);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 500;
  color: var(--accent); flex-shrink: 0;
  font-family: 'DM Mono', monospace;
}
.client-info { flex: 1; }
.client-name { font-size: 15px; font-weight: 500; }
.client-count { font-size: 12px; color: var(--text2); margin-top: 3px; }

/* ===== REPORTS ===== */
.reports-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.report-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 16px;
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
  text-align: center;
}
.report-card:active { background: var(--surface); }
.report-icon { font-size: 28px; margin-bottom: 10px; }
.report-card h3 { font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.report-card p { font-size: 12px; color: var(--text2); }
.report-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.report-table th {
  text-align: left; padding: 8px 12px;
  color: var(--text2); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border2);
  background: var(--bg3);
}
.report-table th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.report-table th:last-child { border-radius: 0 var(--radius-sm) 0 0; }
.report-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.report-table tr:last-child td { border-bottom: none; }
.report-table-wrap {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; margin-top: 16px;
}
.report-header {
  padding: 14px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.report-header h3 { font-size: 14px; font-weight: 500; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 200;
  padding: 0;
}
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
  width: 100%; max-width: 500px;
  max-height: 85vh; overflow-y: auto;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); opacity: 0; } }
.modal-title { font-size: 16px; font-weight: 500; margin-bottom: 16px; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 12px); left: 50%;
  transform: translateX(-50%);
  background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text); font-size: 13px;
  padding: 10px 18px; border-radius: 20px;
  z-index: 500; white-space: nowrap;
  animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }
.toast.success { border-color: rgba(62,207,142,0.3); color: var(--green); }
.toast.error { border-color: rgba(242,107,91,0.3); color: var(--red); }

/* ===== STATES ===== */
.empty-state {
  text-align: center; padding: 40px 20px;
  display: flex; flex-direction: column;
  align-items: center; gap: 12px;
}
.empty-icon { font-size: 40px; }
.empty-state p { color: var(--text2); font-size: 14px; }
.loading-state { text-align: center; padding: 40px; color: var(--text2); font-size: 14px; }

/* ===== ANIMATIONS ===== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.stagger-1 { animation-delay: 0.05s; }
.stagger-2 { animation-delay: 0.10s; }
.stagger-3 { animation-delay: 0.15s; }
.stagger-4 { animation-delay: 0.20s; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 2px; }

/* ===== INPUT AUTOFILL OVERRIDE ===== */
input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--bg3) inset;
  -webkit-text-fill-color: var(--text);
}

/* ===== RESPONSIVE ===== */
#screen-app { width: 100%; height: 100%; }

@media (min-width: 480px) {
  .modal-box { border-radius: var(--radius); margin: 20px; max-height: 90vh; }
  .modal-overlay { align-items: center; }
}

@media (min-width: 700px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .page { padding: 24px 32px 32px; }
  .asset-list { display: grid; grid-template-columns: repeat(2, 1fr); }
  .field-row { grid-template-columns: repeat(3, 1fr); }
  .reports-grid { grid-template-columns: repeat(4, 1fr); }
  .form-section { padding: 22px 24px; }
  #main-content { display: flex; flex-direction: column; }
}

/* ===== GOOGLE AUTH BUTTON ===== */
.btn-google {
  width: 100%;
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}
.btn-google:hover { background: #f8f9fa; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.btn-google:active { transform: scale(0.98); background: #f1f3f4; }
.btn-google:disabled { opacity: 0.6; cursor: not-allowed; }

.auth-security-info {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 16px;
  font-size: 11px; color: var(--text3);
  font-family: 'DM Mono', monospace;
  letter-spacing: 0.02em;
}

/* User avatar in topbar */
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  overflow: hidden; border: 1.5px solid var(--border2);
  flex-shrink: 0; cursor: pointer;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-avatar-initials {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 500;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; cursor: pointer;
  font-family: 'DM Mono', monospace;
}
