:root {
  --bg: #0f1419;
  --card: #1a2332;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9bb4;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,.35);
  --font: "Vazirmatn", "Tahoma", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }

/* Header */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: .75rem 0;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn .ico {
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

/* User dropdown */
.user-menu {
  position: relative;
}
.user-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
}
.user-menu-label {
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-role-badge {
  font-size: .7rem;
  padding: .1rem .4rem;
  border-radius: 999px;
  background: rgba(59,130,246,.15);
  color: #93c5fd;
  border: 1px solid rgba(59,130,246,.25);
}
.user-menu-toggle .chev {
  opacity: .7;
  transition: transform .15s;
}
.user-menu.open .user-menu-toggle .chev {
  transform: rotate(180deg);
}
.user-dropdown {
  position: absolute;
  top: calc(100% + .4rem);
  left: 0;
  min-width: 220px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: .4rem;
  z-index: 80;
}
.user-dropdown[hidden] {
  display: none !important;
}
.user-dropdown-head {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  padding: .55rem .7rem .65rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: .25rem;
}
.user-dropdown-head strong {
  font-size: .95rem;
}
.user-dropdown-head .muted {
  color: var(--muted);
  font-size: .78rem;
  margin: 0;
}
.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .55rem .7rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: .88rem;
}
.user-dropdown-item:hover {
  background: rgba(148,163,184,.12);
  text-decoration: none;
  color: var(--text);
}
.user-dropdown-sep {
  height: 1px;
  background: var(--border);
  margin: .3rem .4rem;
}
.user-dropdown-danger {
  color: #f87171;
}
.user-dropdown-danger:hover {
  background: rgba(239,68,68,.12);
  color: #f87171;
}

/* Auth */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin:0 0 .25rem; font-size: 1.4rem; }
.muted {color: #22c55e;margin: 0 0 1.25rem;}

/* Forms */
label {
  display: block;
  margin-bottom: 1rem;
  font-size: .9rem;
  color: var(--muted);
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="file"],
select,
textarea {
  width: 100%;
  margin-top: .35rem;
  padding: .65rem .85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0d1218;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}
textarea { min-height: 100px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.25);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .55rem 1rem;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: .9rem;
  cursor: pointer;
  background: var(--border);
  color: var(--text);
  transition: background .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: #16a34a; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: #d97706; color: #fff; }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border: 1px solid var(--border); }

/* Alerts */
.alert {
  padding: .75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.alert-success { background: rgba(34,197,94,.15); border: 1px solid rgba(34,197,94,.4); }
.alert-error { background: rgba(239,68,68,.15); border: 1px solid rgba(239,68,68,.4); }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: .75rem;
  margin: 1.25rem 0;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem;
  text-align: center;
}
.stat-card .num { font-size: 1.5rem; font-weight: 700; display: block; }
.stat-card .lbl { font-size: .75rem; color: var(--muted); }
.stat-card.danger .num { color: var(--danger); }
.stat-card.warning .num { color: var(--warning); }
.stat-card.ok .num { color: var(--success); }

/* Toolbar / Search */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
  align-items: center;
}
.search-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  flex: 1;
}
.search-group {
  display: flex;
  align-items: stretch;
  flex: 1;
  max-width: 420px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #0d1218;
  transition: border-color .15s, box-shadow .15s;
}
.search-group:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.25);
}
.search-group input[type="search"] {
  flex: 1;
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  min-width: 0;
  padding: .65rem .85rem;
}
.search-group input[type="search"]:focus {
  outline: none;
  box-shadow: none;
  border: none;
}
.search-group .btn {
  border-radius: 0;
  flex-shrink: 0;
  padding: .55rem 1.1rem;
}
.search-count {
  font-size: .8rem;
  white-space: nowrap;
}
#live-search-clear {
  border: none;
  background: transparent;
  color: var(--muted);
  min-width: 2.2rem;
}
#live-search-clear:hover {
  color: var(--text);
  background: rgba(148,163,184,.12);
}

/* Table / Cards */
.domain-list { display: flex; flex-direction: column; gap: .75rem; }
.domain-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .75rem;
  align-items: start;
}
.domain-row.inactive { opacity: .65; }
.domain-main h3 {
  margin: 0 0 .35rem;
  font-size: 1.1rem;
  word-break: break-all;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem .85rem;
  font-size: .85rem;
  color: var(--muted);
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
}
.st-ok { background: rgba(34,197,94,.15); color: #4ade80; }
.st-soon { background: rgba(234,179,8,.15); color: #facc15; }
.st-tomorrow, .st-today { background: rgba(249,115,22,.15); color: #fb923c; }
.st-overdue { background: rgba(239,68,68,.15); color: #f87171; }
.st-inactive { background: rgba(148,163,184,.15); color: #94a3b8; }

.domain-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  justify-content: flex-end;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 1rem; font-size: 1.2rem; padding-left: 2rem; }
.modal-close {
  position: absolute;
  top: .75rem;
  left: .75rem;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.modal-close:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}
.modal-actions {
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

/* Validation */
input.is-invalid,
select.is-invalid,
textarea.is-invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2) !important;
}
.field-error {
  display: block;
  margin-top: .35rem;
  font-size: .8rem;
  color: #f87171;
  min-height: 0;
}
.field-error:empty {
  display: none;
}
.field-hint {
  display: block;
  margin-top: .3rem;
  font-size: .75rem;
  color: var(--muted);
  line-height: 1.4;
}
.countdown-pill {
  display: inline-flex;
  align-items: center;
  padding: .15rem .55rem;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.12);
  color: #93c5fd;
  font-weight: 600;
  font-size: .8rem;
}
.domain-row.row-urgent .countdown-pill {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
}
.domain-row.row-overdue .countdown-pill {
  background: rgba(239, 68, 68, 0.18);
  color: #f87171;
}

/* Detail panel */
.detail-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.history-list {
  list-style: none;
  padding: 0;
  margin: .75rem 0 0;
}
.history-list li {
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
  color: var(--muted);
}
.history-list li:last-child { border-bottom: none; }

.notes-preview {
  margin-top: .5rem;
  font-size: .85rem;
  color: var(--muted);
  white-space: pre-wrap;
}

.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--text);
  cursor: pointer;
}
.checkbox-label input { width: auto; margin: 0; }

footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
  font-size: .8rem;
}

/* Stat cards clickable */
a.stat-card {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
a.stat-card:hover {
  border-color: var(--primary);
  text-decoration: none;
}
a.stat-card.stat-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59,130,246,.35);
}

/* Domain row + number */
.domain-row {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.domain-row.row-overdue .domain-card {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.35);
}
.domain-row.row-overdue .inline-detail {
  background: rgba(239, 68, 68, 0.06);
  border-color: rgba(239, 68, 68, 0.28);
}
.domain-row.row-urgent .domain-card {
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.35);
}
.domain-row.row-urgent .inline-detail {
  background: rgba(245, 158, 11, 0.06);
  border-color: rgba(245, 158, 11, 0.28);
}
.domain-card {
  grid-template-columns: auto 1fr auto;
  align-items: center;
}
.row-num {
  width: 2rem;
  min-width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(148,163,184,.12);
  color: var(--muted);
  font-size: .85rem;
  font-weight: 700;
}
.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  text-align: right;
}
.link-btn:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* Inline detail under row */
.inline-detail {
  margin: 0 0 .75rem;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-top: none;
  background: #141c28;
}
.domain-row.is-open .domain-card {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: transparent;
}
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-bottom: .75rem;
}
.history-title {
  margin: 1rem 0 .5rem;
  font-size: 1rem;
}
.user-tag {
  color: var(--primary);
  font-weight: 600;
}

input[type="date"] {
  width: 100%;
  margin-top: .35rem;
  padding: .65rem .85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0d1218;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  color-scheme: dark;
}
