:root {
  /* lets the browser paint native controls (select popups, scrollbars,
     checkboxes) with the right theme instead of guessing light/white */
  color-scheme: light dark;

  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --sidebar-bg: #1b2030;
  --sidebar-text: #c7cbd6;
  --sidebar-active-bg: #2f6fed;
  --sidebar-active-text: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e2e4e9;
  --primary: #2f6fed;
  --primary-hover: #2559c4;
  --danger: #d64545;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --card-bg: #1d2029;
    --sidebar-bg: #10121a;
    --sidebar-text: #9aa1ae;
    --sidebar-active-bg: #5b8bf0;
    --sidebar-active-text: #0e1116;
    --text: #eef0f4;
    --muted: #9aa1ae;
    --border: #2b2f3a;
    --primary: #5b8bf0;
    --primary-hover: #7ba0f3;
    --danger: #f27272;
  }
}

@font-face {
  font-family: "IRANSans";
  src: url("fonts/IRANSans(FaNum)_Light.ttf") format("truetype");
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IRANSans";
  src: url("fonts/IRANSans.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IRANSans";
  src: url("fonts/IRANSans(FaNum)_Medium.ttf") format("truetype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IRANSans";
  src: url("fonts/IRANSans(FaNum)_Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }

/* .login-wrap/.app-shell below set their own `display`, which — being an
   author-stylesheet rule — outranks the browser's default `[hidden]{display:none}`
   (a user-agent rule) despite matching specificity. Without this, toggling
   `.hidden` in JS has no visual effect and both views stay on screen. */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IRANSans", Tahoma, "Segoe UI", sans-serif;
}

button, input {
  font-family: inherit;
}

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

.card h1 {
  font-size: 1.4rem;
  margin: 0 0 4px;
}

.subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 0.9rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

input {
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
}

input:focus {
  outline: none;
  border-color: var(--primary);
}

/* native <select> popup: without an explicit background, some browsers
   render it opaque white regardless of theme, swallowing light text in
   dark mode. Style the option list explicitly so it always matches. */
option {
  background: var(--card-bg);
  color: var(--text);
}

button {
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

button:hover { background: var(--primary-hover); }

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0;
}

/* ---------- App shell ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 20px;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: bold;
  flex-shrink: 0;
}

.brand-name {
  font-size: 1rem;
  font-weight: bold;
  color: #fff;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 12px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.9rem;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

.nav-icon {
  font-size: 0.95rem;
  width: 1.2em;
  text-align: center;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.topbar h2 {
  margin: 0;
  font-size: 1.1rem;
}

.profile {
  position: relative;
}

.profile-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px 6px 12px;
  color: var(--text);
  cursor: pointer;
}

.profile-btn:hover {
  background: rgba(0, 0, 0, 0.03);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: bold;
  flex-shrink: 0;
}

.profile-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.3;
}

.profile-name {
  font-size: 0.85rem;
}

.profile-username {
  font-size: 0.75rem;
  color: var(--muted);
}

.chevron {
  color: var(--muted);
  font-size: 0.75rem;
}

.profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 140px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  z-index: 10;
}

.profile-menu button {
  width: 100%;
  text-align: right;
  background: transparent;
  color: var(--danger);
  border: none;
  border-radius: 0;
  padding: 10px 14px;
  font-size: 0.85rem;
}

.profile-menu button:hover {
  background: rgba(0, 0, 0, 0.05);
}

.profile-menu button.profile-menu-neutral {
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.content {
  flex: 1;
  padding: 28px;
}

.welcome-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
}

.welcome-card h1 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.placeholder {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

/* ---------- Pages ---------- */

.card-block {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 320px;
}

.field select,
.field input {
  font-size: 0.95rem;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
}

.field select:focus,
.field input:focus {
  outline: none;
  border-color: var(--primary);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px 20px;
  align-items: end;
}

.form-grid .field {
  max-width: none;
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  color: var(--text);
  font-size: 0.9rem;
}

.form-grid button {
  height: 40px;
  align-self: end;
}

.form-grid .hint {
  grid-column: 1 / -1;
}

.hint {
  width: 100%;
  font-size: 0.85rem;
  margin: 4px 0 0;
  color: var(--muted);
}

.hint.success { color: #1a9d5c; }
.hint.error { color: var(--danger); }

.table-scroll {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th,
.data-table td {
  text-align: right;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  color: var(--muted);
  font-weight: 500;
}

.data-table .cost-input {
  width: 110px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.85rem;
}

.data-table .cost-input:disabled {
  opacity: 0.5;
}

.table-action-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
}

.table-action-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

/* toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  vertical-align: middle;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s;
}

.switch .slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  right: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}

.switch input:checked + .slider {
  background: var(--primary);
}

.switch input:checked + .slider::before {
  transform: translateX(-18px);
}

.switch input:disabled + .slider {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Credentials modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.modal-box {
  width: 100%;
  max-width: 460px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-box h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.modal-warning {
  background: rgba(214, 69, 69, 0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 8px;
  padding: 12px;
  font-size: 0.85rem;
  line-height: 1.7;
  margin: 0 0 20px;
}

.credential-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.credential-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.credential-value {
  font-family: "Courier New", monospace;
  font-size: 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  word-break: break-all;
  direction: ltr;
  text-align: left;
}

.modal-box button {
  width: 100%;
  margin-top: 8px;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions button {
  width: auto;
  flex: 1;
  margin-top: 0;
}
