:root {
  --bg-deep: #0a0e1a;
  --bg-elevated: #121729;
  --glass: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.12);
  --text-primary: #f4f6fb;
  --text-secondary: #97a1bd;
  --text-dim: #616b8a;
  --accent-orange: #ff7a45;
  --accent-orange-dim: rgba(255, 122, 69, 0.15);
  --green-a: #11998e;
  --green-b: #38ef7d;
  --purple-a: #7f53ac;
  --purple-b: #647dee;
  --blue-a: #2193b0;
  --blue-b: #6dd5ed;
  --pink-a: #f857a6;
  --pink-b: #ff5858;
  --amber-a: #f7971e;
  --amber-b: #ffd200;
  --teal-a: #0acffe;
  --teal-b: #495aff;
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(ellipse at top, #161d34 0%, var(--bg-deep) 55%);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100vh;
  overscroll-behavior-y: contain;
}

h1, h2, h3, .display {
  font-family: 'Sora', 'Inter', sans-serif;
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  padding-bottom: calc(96px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
}

/* ---------- Desktop sidebar (hidden on mobile) ---------- */
.sidebar-nav { display: none; }

@media (min-width: 900px) {
  html, body { background: var(--bg-deep); }

  .page-wrap {
    max-width: 1080px;
    margin: 0 auto;
    display: flex;
    align-items: flex-start;
    gap: 36px;
    padding: 40px 32px;
    min-height: 100vh;
  }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    width: 220px;
    flex-shrink: 0;
    position: sticky;
    top: 40px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 20px 14px;
    gap: 4px;
  }

  .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 10px 20px;
  }
  .sidebar-brand .title { font-family: 'Sora', sans-serif; font-weight: 700; font-size: 17px; }
  .sidebar-brand .subtitle { font-size: 12px; color: var(--text-secondary); }

  .sidebar-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 14px;
    border-radius: 14px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
  }
  .sidebar-btn .nav-icon { font-size: 18px; }
  .sidebar-btn:hover { background: rgba(255,255,255,0.06); }
  .sidebar-btn.active {
    color: white;
    background: linear-gradient(135deg, var(--purple-a), var(--blue-b));
  }

  .app-shell {
    max-width: 640px;
    margin: 0;
    padding-bottom: 40px;
    flex: 1;
  }

  .app-header { display: none; }
  .bottom-nav { display: none; }

  .tab-panel { padding: 4px 0 0; }

  .currency-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .keypad { max-width: 360px; }
  .tools-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 1180px) {
  .app-shell { max-width: 760px; }
  .tools-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Header ---------- */
.app-header {
  padding: 22px 20px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header .brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--purple-a), var(--blue-b));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 8px 20px rgba(100, 125, 238, 0.35);
}

.brand-text .title {
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.2px;
}

.brand-text .subtitle {
  font-size: 12.5px;
  color: var(--text-secondary);
}

.header-icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  font-size: 17px;
}

/* ---------- Tab panels ---------- */
.tab-panel { display: none; padding: 4px 16px 16px; flex: 1; }
.tab-panel.active { display: block; animation: fadeUp 0.28s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Glass card base ---------- */
.glass-card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

/* ---------- Currency rows (Asosiy) ---------- */
.rows-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 4px 14px;
}

.rows-header h2 {
  font-size: 15px;
  color: var(--text-secondary);
  font-weight: 600;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.add-row-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--purple-a), var(--blue-b));
  color: white;
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 18px rgba(100, 125, 238, 0.3);
  cursor: pointer;
}
.add-row-btn:active { transform: scale(0.94); }

.currency-rows { display: flex; flex-direction: column; gap: 12px; }

.currency-row {
  position: relative;
  border-radius: var(--radius-md);
  padding: 16px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  overflow: hidden;
  isolation: isolate;
}

.currency-row::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.85;
  z-index: -1;
}
.currency-row.grad-0::before { background: linear-gradient(120deg, var(--green-a), var(--green-b)); }
.currency-row.grad-1::before { background: linear-gradient(120deg, var(--purple-a), var(--purple-b)); }
.currency-row.grad-2::before { background: linear-gradient(120deg, var(--blue-a), var(--blue-b)); }
.currency-row.grad-3::before { background: linear-gradient(120deg, var(--pink-a), var(--pink-b)); }
.currency-row.grad-4::before { background: linear-gradient(120deg, var(--amber-a), var(--amber-b)); }
.currency-row.grad-5::before { background: linear-gradient(120deg, var(--teal-a), var(--teal-b)); }

.row-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row-flag { font-size: 26px; line-height: 1; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25)); }

.row-select-btn {
  background: rgba(255,255,255,0.18);
  border: none;
  color: white;
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 16px;
  padding: 6px 10px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.row-select-btn .caret { font-size: 11px; opacity: 0.85; }
.row-name-caption {
  font-size: 11.5px;
  color: rgba(255,255,255,0.85);
  margin-top: 3px;
}

.row-right { text-align: right; min-width: 0; flex: 1; }
.row-value {
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 22px;
  color: white;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-remove {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.25);
  color: rgba(255,255,255,0.8);
  font-size: 13px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.currency-rows.editable .row-remove { display: flex; }

.source-note {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-dim);
  margin: 16px 0 6px;
}

/* ---------- Keypad ---------- */
.keypad {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr) 78px;
  grid-auto-rows: 56px;
  gap: 10px;
}
.key {
  border: none;
  border-radius: var(--radius-sm);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  font-family: 'Sora', sans-serif;
  font-size: 21px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.key:active { background: rgba(255,255,255,0.14); }
.key.key-ac, .key.key-back {
  grid-column: 4;
  color: var(--accent-orange);
  background: var(--accent-orange-dim);
  border: 1px solid rgba(255,122,69,0.25);
  font-size: 15px;
  font-weight: 700;
}
.key.key-ac { grid-row: 1 / span 2; border-radius: 30px; }
.key.key-back { grid-row: 3 / span 2; border-radius: 30px; font-size: 19px; }
.key.key-zero { grid-column: 1 / span 2; }

/* ---------- Modal: currency picker ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4,6,14,0.72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal-overlay.open { display: flex; }
.modal-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  border-radius: 28px 28px 0 0;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0.4; } to { transform: translateY(0); opacity: 1; } }

.modal-handle { width: 40px; height: 4px; background: var(--glass-border); border-radius: 3px; margin: 12px auto 6px; }
.modal-title { text-align: center; font-family: 'Sora', sans-serif; font-weight: 700; font-size: 16px; padding: 4px 16px 12px; }
.modal-search {
  margin: 0 16px 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  font-size: 15px;
}
.modal-search:focus { outline: none; border-color: var(--purple-b); }
.modal-list { overflow-y: auto; padding: 0 8px 8px; }
.modal-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px;
  border-radius: 14px;
  cursor: pointer;
}
.modal-list-item:active, .modal-list-item:hover { background: var(--glass); }
.modal-list-item .flag { font-size: 24px; }
.modal-list-item .names { display: flex; flex-direction: column; min-width: 0; }
.modal-list-item .uz-name { font-size: 14.5px; font-weight: 600; }
.modal-list-item .code { font-size: 12px; color: var(--text-secondary); }
.modal-cancel {
  margin: 6px 16px calc(16px + var(--safe-bottom));
  padding: 14px;
  border-radius: 16px;
  border: none;
  background: var(--glass);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.empty-state { text-align: center; color: var(--text-dim); padding: 30px 20px; font-size: 14px; }

/* ---------- History tab ---------- */
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
}
.history-item .h-left { display: flex; flex-direction: column; gap: 3px; }
.history-item .h-pair { font-family: 'Sora', sans-serif; font-weight: 700; font-size: 15px; }
.history-item .h-time { font-size: 12px; color: var(--text-secondary); }
.history-item .h-remove { background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer; padding: 4px 8px; }
.history-clear {
  width: 100%;
  margin-top: 6px;
  padding: 13px;
  border-radius: 16px;
  border: 1px solid rgba(255,122,69,0.3);
  background: var(--accent-orange-dim);
  color: var(--accent-orange);
  font-weight: 600;
  cursor: pointer;
}

/* ---------- More tools grid ---------- */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 10px;
}
.tool-tile {
  aspect-ratio: 1 / 0.92;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  text-align: center;
  padding: 8px;
}
.tool-tile .tool-icon { font-size: 26px; }
.tool-tile .tool-label { font-size: 12px; font-weight: 600; color: var(--text-primary); line-height: 1.2; }

/* ---------- Tool detail view ---------- */
.tool-view { display: none; }
.tool-view.active { display: block; animation: fadeUp 0.25s ease; }
.tool-back {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 14px;
  cursor: pointer;
}
.tool-header { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.tool-header .tool-icon-lg {
  width: 44px; height: 44px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
  background: linear-gradient(135deg, var(--purple-a), var(--blue-b));
}
.tool-header h2 { margin: 0; font-size: 18px; }

.unit-row {
  padding: 16px;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}
.unit-row select {
  width: 100%;
  background: rgba(255,255,255,0.12);
  border: none;
  color: white;
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 14.5px;
  padding: 8px 10px;
  border-radius: 10px;
  margin-bottom: 8px;
}
.unit-row input {
  width: 100%;
  background: transparent;
  border: none;
  color: white;
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 26px;
  text-align: right;
}
.unit-row input:focus { outline: none; }

.calc-display {
  padding: 24px 20px;
  border-radius: var(--radius-lg);
  text-align: right;
  font-family: 'Sora', sans-serif;
  font-size: 40px;
  font-weight: 700;
  margin-bottom: 14px;
  word-break: break-all;
  background: linear-gradient(120deg, var(--blue-a), var(--purple-b));
}
.calc-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.calc-key {
  height: 60px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text-primary);
  font-family: 'Sora', sans-serif;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
}
.calc-key.op { background: var(--accent-orange-dim); color: var(--accent-orange); border-color: rgba(255,122,69,0.3); }
.calc-key.eq { background: linear-gradient(135deg, var(--purple-a), var(--blue-b)); color: white; border: none; }

.simple-field { margin-bottom: 14px; }
.simple-field label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; font-weight: 600; }
.simple-field input, .simple-field select {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text-primary);
  font-size: 16px;
  font-family: 'Inter', sans-serif;
}
.simple-field input:focus, .simple-field select:focus { outline: none; border-color: var(--purple-b); }

.result-card {
  padding: 20px;
  border-radius: var(--radius-md);
  text-align: center;
  margin-top: 8px;
}
.result-card .result-value { font-family: 'Sora', sans-serif; font-weight: 800; font-size: 30px; }
.result-card .result-label { font-size: 12.5px; color: rgba(255,255,255,0.85); margin-top: 4px; }

.bmi-scale { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; font-size: 12.5px; }
.bmi-scale .scale-row { display: flex; justify-content: space-between; padding: 8px 12px; border-radius: 10px; background: var(--glass); }

/* ---------- Kirish / Ro'yxatdan o'tish ekrani ---------- */
.auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at top, #161d34 0%, var(--bg-deep) 55%);
  z-index: 100;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 32px 26px;
  border-radius: var(--radius-lg);
}
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}
.auth-brand .brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--purple-a), var(--blue-b));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}
.auth-brand .title { font-family: 'Sora', sans-serif; font-weight: 700; font-size: 20px; }

.auth-view { display: none; }
.auth-view.active { display: block; animation: fadeUp 0.25s ease; }

.auth-switch-link {
  display: block;
  text-align: center;
  color: var(--blue-b);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  margin-bottom: 18px;
}
.auth-switch-link:hover { text-decoration: underline; }

.auth-error {
  min-height: 0;
  font-size: 13px;
  color: var(--pink-b);
  text-align: center;
  margin: 2px 0 4px;
  display: none;
}
.auth-error.visible { display: block; min-height: 18px; }

.auth-delete-btn {
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  border-radius: 14px;
  border: 1px solid rgba(255,122,69,0.25);
  background: var(--accent-orange-dim);
  color: var(--accent-orange);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.auth-submit-btn {
  width: 100%;
  padding: 14px;
  border-radius: 16px;
  border: none;
  background: linear-gradient(135deg, var(--purple-a), var(--blue-b));
  color: white;
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.auth-submit-btn:active { transform: scale(0.98); }

/* ---------- Profil sahifasi ---------- */
.profile-card {
  padding: 24px 20px;
  border-radius: var(--radius-lg);
}
.profile-avatar-wrap {
  position: relative;
  width: 96px;
  height: 96px;
  margin: 0 auto 22px;
}
.profile-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple-a), var(--blue-b));
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 34px;
  color: white;
}
.profile-avatar-edit {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-orange);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  cursor: pointer;
  border: 3px solid var(--bg-elevated);
}
.auth-success {
  min-height: 0;
  font-size: 13px;
  color: var(--green-b);
  text-align: center;
  margin: 2px 0 4px;
  display: none;
}
.auth-success.visible { display: block; min-height: 18px; }

.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + var(--safe-bottom));
  width: calc(100% - 32px);
  max-width: 448px;
  background: rgba(18, 23, 41, 0.85);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 22px;
  display: flex;
  padding: 8px;
  gap: 6px;
  z-index: 40;
  box-shadow: 0 12px 30px rgba(0,0,0,0.4);
}
.nav-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 4px;
  border-radius: 16px;
  cursor: pointer;
  font-size: 11.5px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
}
.nav-btn .nav-icon { font-size: 19px; }
.nav-btn.active {
  color: white;
  background: linear-gradient(135deg, var(--purple-a), var(--blue-b));
}

/* scrollbar tidy */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

@media (max-width: 360px) {
  .row-value { font-size: 19px; }
  .calc-display { font-size: 32px; }
}
