@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap');

:root {
  font: 14px/1.7 "Vazirmatn", system-ui, -apple-system, sans-serif;
  color: #0F172A;
  background-color: #F8FAFC;

  /* Design Tokens (Executive Slate & Precision Legal Teal) */
  --bg-app: #F8FAFC;
  --bg-card: #FFFFFF;
  --ink-primary: #0F172A;
  --ink-secondary: #334155;
  --ink-muted: #64748B;
  --border: #E2E8F0;
  --input: #E2E8F0;
  --ring: #0F172A;
  --primary: #0F172A;
  --primary-foreground: #FFFFFF;
  --primary-hover: #1E293B;
  --secondary: #F1F5F9;
  --secondary-foreground: #0F172A;
  --teal-accent: #257C80;
  --teal-subtle: #EAF3F2;

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-card: 16px;

  --shadow-card: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 12px 28px -6px rgba(15, 23, 42, 0.06);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* Compatibility mappings */
  --ink: var(--ink-primary);
  --muted: var(--ink-muted);
  --line: var(--border);
  --teal: var(--teal-accent);
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: var(--bg-app);
  color: var(--ink-primary);
  direction: rtl;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

button, a, input {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

button:focus-visible, a:focus-visible, input:focus-visible, .table-wrap:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

input:focus-visible {
  outline-offset: 0;
  border-color: var(--ring);
}

button:active:not(:disabled) {
  opacity: 0.85;
}

.account-shell {
  max-width: 1200px;
  margin: auto;
  padding: 28px 40px;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.3;
  flex-shrink: 0;
  color: var(--ink-primary);
}

.brand img {
  object-fit: contain;
}

.brand small {
  display: block;
  font-size: 11px;
  color: var(--ink-muted);
  font-weight: 400;
  margin-top: 4px;
}

.header-actions {
  display: flex;
  gap: 20px;
  align-items: center;
}

.workspace-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
  transition: color 140ms ease;
}

.workspace-link span {
  margin-inline-start: 6px;
}

.quiet-button {
  border: 0;
  background: none;
  color: var(--ink-muted);
  font-size: 13px;
  padding: 8px 0;
  transition: color 140ms ease;
}

.eyebrow {
  font-size: 12px;
  font-weight: 600;
  color: var(--teal-accent);
  margin: 0 0 12px;
  display: inline-block;
}

/* ==========================================================================
   Login Layout - Right-Hand Side Card in RTL
   ========================================================================== */
.login-layout {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  align-items: center;
  gap: clamp(40px, 7vw, 96px);
  flex: 1;
  padding-block: 56px;
}

/* Card Section (on the Right in RTL) */
.login-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 36px 38px;
  box-shadow: var(--shadow-card);
  position: relative;
}

.login-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid #D9E8E9;
  border-radius: var(--radius-md);
  color: var(--teal-accent);
  margin-bottom: 24px;
  background: var(--teal-subtle);
}

.login-panel .eyebrow {
  font-size: 11px;
  margin-bottom: 6px;
}

h2 {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: -0.02em;
  color: var(--ink-primary);
  margin: 0;
}

.muted {
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 1.8;
}

.login-panel > .muted {
  margin: 8px 0 24px;
}

label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-primary);
  margin: 18px 0 6px;
}

label span {
  font-size: 11px;
  font-weight: 400;
  color: var(--ink-muted);
}

input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background: #FFFFFF;
  color: var(--ink-primary);
  padding: 8px 14px;
  font-size: 14px;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input::placeholder {
  color: var(--ink-muted);
  opacity: 0.7;
  font-size: 12px;
}

input:read-only {
  background: #F1F5F9;
  color: var(--ink-muted);
}

.password-field {
  position: relative;
}

.password-field input {
  padding-inline-end: 64px;
}

.password-field button {
  position: absolute;
  inset-inline-start: 8px;
  top: 0;
  bottom: 0;
  border: 0;
  background: transparent;
  font-size: 11px;
  font-weight: 500;
  color: var(--teal-accent);
  padding: 8px;
}

.primary-button, .secondary-button {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  border-radius: var(--radius-md);
  min-height: 44px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: all 140ms ease;
  user-select: none;
}

.primary-button {
  background: var(--primary);
  color: var(--primary-foreground);
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.secondary-button {
  background: #FFFFFF;
  border-color: var(--border);
  color: var(--ink-secondary);
}

#submit {
  margin-top: 24px;
  width: 100%;
  justify-content: space-between;
  min-height: 46px;
}

#submit > span:last-child {
  font: 18px system-ui;
}

.footnote {
  border-top: 1px solid var(--border);
  padding-top: 18px;
  font-size: 11px;
  color: var(--ink-muted);
  line-height: 1.8;
  margin: 24px 0 0;
}

.feedback {
  font-size: 12px;
  background: var(--teal-subtle);
  border-radius: var(--radius-sm);
  padding: 12px;
  color: var(--teal-accent);
  margin: 16px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.feedback:empty {
  display: none;
}

.feedback[data-error="true"] {
  background: #FEF2F2;
  color: #DC2626;
  border: 1px solid #FECACA;
}

/* Signed In State */
#signed-in {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.identity {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--secondary);
  color: var(--ink-primary);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  margin: 0 0 14px;
  overflow-wrap: anywhere;
}

#signed-in .primary-button {
  width: 100%;
  justify-content: center;
  min-height: 44px;
  font-size: 13px;
  font-weight: 600;
  background: var(--primary);
  color: var(--primary-foreground);
  border: 1px solid var(--primary);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.text-link {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
  padding: 10px 14px;
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all 140ms ease;
  margin-top: 2px;
}

#signed-in .secondary-button {
  width: 100%;
  justify-content: center;
  min-height: 38px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-muted);
  background: transparent;
  border-color: transparent;
  margin-top: 4px;
}

/* Welcome Section (on the Left in RTL) */
.welcome {
  display: flex;
  flex-direction: column;
}

.welcome .eyebrow {
  margin-bottom: 14px;
}

.welcome h1 {
  font-size: clamp(34px, 3.8vw, 48px);
  line-height: 1.4;
  letter-spacing: -0.03em;
  font-weight: 700;
  color: var(--ink-primary);
  margin: 0 0 16px;
}

.welcome > p {
  color: var(--ink-muted);
  font-size: 14px;
  line-height: 2.1;
  max-width: 420px;
  margin: 0;
}

.document-figure {
  margin-top: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #FFFFFF;
  max-width: 370px;
  padding: 22px 24px;
  box-shadow: var(--shadow-card);
  transform: rotate(1.5deg);
  transition: transform 200ms ease;
}

.document-figure:hover {
  transform: rotate(0deg);
}

.figure-header {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-muted);
  font-weight: 500;
}

.figure-rule {
  height: 1px;
  background: var(--border);
  margin: 16px 0 20px;
}

.figure-line {
  height: 6px;
  background: #E2E8F0;
  border-radius: 3px;
  width: 62%;
  margin: 9px 0;
}

.figure-line.short {
  width: 40%;
  margin-bottom: 20px;
  background: #F1F5F9;
}

.figure-row {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid #F1F5F9;
  padding: 12px 0;
  font-size: 12px;
  color: var(--ink-secondary);
}

.figure-bottom {
  font-size: 11px;
  color: var(--ink-muted);
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 7px;
  height: 7px;
  display: inline-block;
  border-radius: 50%;
  background: var(--teal-accent);
  flex-shrink: 0;
}

.welcome-note {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 32px;
}

.note-line {
  width: 28px;
  height: 1px;
  background: #CBD5E1;
}

footer {
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--ink-muted);
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

footer > span:first-child {
  font-weight: 600;
}

/* ==========================================================================
   Admin Management Section
   ========================================================================== */
.admin-page .login-layout {
  display: none;
}

.admin-page .account-shell {
  max-width: 1360px;
}

#management {
  padding-block: 38px 48px;
  flex: 1;
}

.management-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 28px;
}

.management-heading h1 {
  font-size: 28px;
  line-height: 1.5;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
  color: var(--ink-primary);
}

.management-heading p {
  margin: 4px 0;
}

.management-heading .eyebrow {
  margin-bottom: 8px;
  font-size: 11px;
}

.overview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #FFFFFF;
  margin-bottom: 28px;
  box-shadow: var(--shadow-sm);
}

.overview > div {
  padding: 18px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.overview > div + div {
  border-inline-start: 1px solid var(--border);
}

.overview span {
  color: var(--ink-muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.overview strong {
  font-size: 26px;
  line-height: 1.4;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-primary);
}

.management-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.editor, .directory {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-width: 0;
  box-shadow: var(--shadow-sm);
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-heading h2 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--ink-primary);
  margin: 0;
}

.section-number {
  font-size: 11px;
  color: var(--ink-muted);
}

.editor-help, .directory-help {
  font-size: 12px;
  margin: 8px 0 20px;
}

.editor small {
  display: block;
  color: var(--ink-muted);
  font-size: 11px;
  line-height: 1.8;
  margin-top: 6px;
}

.editor label {
  margin-top: 18px;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 24px;
}

.actions .primary-button {
  flex: 1;
}

.actions .secondary-button {
  font-size: 11px;
}

.count-label {
  margin-inline-start: auto;
  font-size: 11px;
  color: var(--ink-muted);
}

.table-wrap {
  overflow-x: auto;
  scrollbar-width: thin;
  position: relative;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: start;
  font-size: 13px;
  min-width: 440px;
}

th {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--bg-app);
  padding: 12px 10px;
  border-block: 1px solid var(--border);
  text-align: start;
}

td {
  padding: 16px 10px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: start;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.user-name {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  background: var(--teal-subtle);
  border: 1px solid #DFEBEB;
  border-radius: var(--radius-md);
  color: var(--teal-accent);
  font-size: 12px;
  font-weight: 600;
}

.username {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: var(--radius-xs);
  background: #F1F5F9;
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
}

.status-badge[data-state="active"] {
  color: #166534;
  background: #F0FDF4;
  border: 1px solid #BBF7D0;
}

.status-badge[data-state="expired"] {
  color: #9A3412;
  background: #FFF7ED;
  border: 1px solid #FFEDD5;
}

.status-badge[data-state="admin"] {
  color: #1E40AF;
  background: #EFF6FF;
  border: 1px solid #DBEAFE;
}

.edit-button {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #FFFFFF;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-secondary);
  transition: all 140ms ease;
}

.empty-state {
  text-align: center;
  padding: 28px 12px;
  font-size: 13px;
  color: var(--ink-muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

/* ==========================================================================
   Hover & Micro-interactions
   ========================================================================== */
@media (hover: hover) and (pointer: fine) {
  .primary-button:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
  }
  .secondary-button:hover, .edit-button:hover {
    background: #F8FAFC;
    border-color: #CBD5E1;
  }
  .workspace-link:hover, .quiet-button:hover {
    color: var(--teal-accent);
  }
  tbody tr:hover {
    background: #F8FAFC;
  }
}

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */
@media (max-width: 1000px) {
  .account-shell {
    padding: 24px;
  }
  .login-layout {
    grid-template-columns: 380px minmax(0, 1fr);
    gap: 36px;
  }
  .management-grid {
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 16px;
  }
  .editor, .directory {
    padding: 20px;
  }
  .overview > div {
    padding: 18px;
  }
  .overview span {
    font-size: 10px;
  }
}

@media (max-width: 760px) {
  .management-grid {
    grid-template-columns: 1fr;
  }
  .editor {
    max-width: none;
  }
  .overview > div {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 16px;
  }
  .management-heading {
    align-items: flex-start;
  }
  .management-heading h1 {
    font-size: 24px;
  }
  .management-heading > .secondary-button {
    font-size: 10px;
    white-space: nowrap;
  }
  .login-layout {
    grid-template-columns: 1fr;
    max-width: 420px;
    margin: auto;
    width: 100%;
    padding: 32px 0;
  }
  .welcome {
    display: none;
  }
  .header-actions {
    gap: 12px;
  }
  .brand small {
    display: none;
  }
  .workspace-link {
    font-size: 11px;
  }
  .login-panel {
    padding: 28px 24px;
  }
  .account-shell {
    padding: 20px;
  }
  footer {
    font-size: 10px;
  }
  .site-header {
    padding-bottom: 20px;
  }
  .login-panel .footnote {
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media (min-width: 761px) and (max-height: 820px) {
  .account-shell { padding-block: 20px; }
  .site-header { padding-bottom: 18px; }
  .login-layout { padding-block: 28px; }
  .login-panel { padding: 28px 32px; }
  .login-mark { display: none; }
  .login-panel > .muted { margin-bottom: 18px; }
  .login-panel label { margin-top: 14px; }
  .login-panel .footnote { margin-top: 18px; padding-top: 14px; }
  .welcome h1 { font-size: 38px; }
  .document-figure { margin-top: 24px; padding: 18px 22px; }
  .welcome-note { margin-top: 24px; }
}
