:root {
  --bg: #f4f2ea;
  --surface: rgba(255, 253, 248, 0.94);
  --line: #d8d2c4;
  --text: #0c3b33;
  --muted: #61756f;
  --accent: #0f5a46;
  --accent-2: #14795f;
  --success: #0a7f55;
  --warning: #b45309;
  --pending: #fef3c7;
  --paid: #dbeafe;
  --done: #dcfce7;
  --shadow: 0 20px 40px rgba(23, 41, 32, 0.06);
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(15, 90, 70, 0.08), transparent 30%),
    linear-gradient(180deg, #f7f4ec 0%, #efe8d7 100%);
}

.hidden {
  display: none !important;
}

.main-shell h1,
.main-shell h2,
.main-shell h3,
.login-panel h2,
.login-hero h1 {
  letter-spacing: -0.02em;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
}

.login-hero {
  background: linear-gradient(180deg, #0f5a46 0%, #1b6d59 100%);
  color: white;
  padding: 72px;
  display: grid;
  align-content: center;
  gap: 24px;
}

.login-hero img {
  width: 64px;
  border-radius: 8px;
}

.login-hero h1 {
  margin: 0;
  font-size: clamp(2.2rem, 4vw, 4rem);
  line-height: 1.1;
  max-width: 580px;
}

.login-hero p {
  margin: 0;
  max-width: 520px;
  color: #d7efe5;
  font-size: 1.15rem;
}

.login-panel {
  padding: 72px min(7vw, 88px);
  display: grid;
  align-content: center;
  gap: 18px;
  background: linear-gradient(180deg, #fffdfa 0%, #f8f4eb 100%);
}

.panel-card,
.card {
  background: var(--surface);
  border: 1px solid rgba(117, 96, 64, 0.16);
  border-radius: 22px;
  padding: 24px;
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

input,
select,
button {
  font: inherit;
  border-radius: 12px;
}

input,
select {
  min-height: 46px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: white;
}

button {
  min-height: 46px;
  border: 0;
  cursor: pointer;
}

.solid-button {
  background: var(--accent);
  color: white;
}

.solid-button:hover {
  background: #0b4c3b;
}

.ghost-button {
  background: white;
  color: var(--text);
  border: 1px solid var(--line);
}

.ghost-button:hover {
  background: #f7f4ec;
}

.link-button {
  background: transparent;
  color: var(--accent);
  padding: 0;
  min-height: auto;
  text-align: left;
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  background: linear-gradient(180deg, #0f5a46 0%, #0c4a3b 100%);
  color: white;
  padding: 28px;
  border-right: 1px solid rgba(255, 255, 255, .08);
}

.brand {
  display: grid;
  gap: 14px;
}

.brand img {
  width: 36px;
  height: 24px;
  border-radius: 4px;
  object-fit: cover;
}

.brand-title {
  margin: 0 0 14px;
  color: #d2f0e4;
  line-height: 1.4;
}

.pill {
  background: rgba(16, 185, 129, 0.18);
  color: white;
  padding: 6px 12px;
  border-radius: 999px;
  display: inline-block;
  font-size: .8rem;
  font-weight: 700;
}

.nav-list {
  margin-top: 36px;
  display: grid;
  gap: 8px;
}

.nav-item {
  padding: 12px 14px;
  border-radius: 14px;
  background: transparent;
  color: white;
  text-align: left;
  font-weight: 600;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, .1);
}

.main-shell {
  padding-bottom: 32px;
}

.topbar {
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.82);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.profile-strip {
  display: flex;
  align-items: center;
  gap: 18px;
}

.profile-copy {
  display: grid;
  justify-items: end;
  gap: 2px;
}

.profile-copy strong {
  font-size: 1.05rem;
}

.role-switcher,
.content-grid {
  padding: 26px 28px 0;
}

.role-switcher {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-size: .74rem;
  color: var(--success);
}

.hero-grid,
.stats-grid,
.dual-grid {
  display: grid;
  gap: 16px;
}

.page-intro {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.page-intro h2 {
  margin: 0 0 6px;
  font-size: 2.25rem;
}

.split-intro {
  align-items: center;
}

.page-intro .muted {
  font-size: 1.05rem;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.justice-stats {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.dual-grid {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.intro-card {
  background: linear-gradient(135deg, rgba(15, 90, 70, 0.08), rgba(255, 255, 255, 0.92));
}

.intro-card h3 {
  margin: 0 0 8px;
  font-size: 2rem;
}

.stat-card strong {
  display: block;
  margin-top: 12px;
  font-size: 2rem;
}

.stat-card {
  min-height: 110px;
  display: grid;
  align-content: center;
}

.chart-card {
  min-height: 360px;
}

.chart-card h3,
.card h3 {
  margin-top: 0;
}

.donut-wrap {
  display: flex;
  justify-content: center;
  padding: 34px 0 18px;
}

.donut-ring {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: conic-gradient(#0f5a46 0 12%, #f59e0b 12% 82%, #1d4ed8 82% 100%);
  position: relative;
}

.donut-ring::after {
  content: "";
  position: absolute;
  inset: 22px;
  background: white;
  border-radius: 50%;
}

.legend-row {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.legend-row span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.legend-paid {
  background: #0f5a46;
}

.legend-completed {
  background: #f59e0b;
}

.legend-pending {
  background: #1d4ed8;
}

.bars {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.government-bars .bar-track,
.region-bars .bar-track {
  height: 16px;
}

.bar-row {
  display: grid;
  gap: 10px;
}

.bar-track {
  background: #e9e2d4;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.list-stack,
.application-list {
  display: grid;
  gap: 14px;
}

.list-meta {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.section-head h3 {
  margin-bottom: 0;
}

.item-row,
.transaction-row,
.application-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid #ece5d8;
}

.transaction-row strong,
.application-row strong {
  font-size: 1rem;
}

.status-chip {
  border-radius: 999px;
  padding: 6px 10px;
  text-transform: uppercase;
  font-size: .75rem;
  font-weight: 700;
}

.status-chip.completed,
.status-chip.active {
  background: var(--done);
  color: var(--success);
}

.status-chip.paid {
  background: var(--paid);
  color: #1d4ed8;
}

.status-chip.pending {
  background: var(--pending);
  color: var(--warning);
}

.status-chip.returned,
.status-chip.rejected {
  background: #fee2e2;
  color: #b91c1c;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1000px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid #ece5d8;
  text-align: left;
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.inline-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.error {
  color: #b91c1c;
}

.success-text {
  color: var(--success);
  font-weight: 700;
}

.creds-card p {
  margin: 6px 0;
}

.small-line {
  font-size: .92rem;
}

.credentials-panel {
  border: 1px solid rgba(15, 90, 70, 0.2);
  background: linear-gradient(180deg, rgba(223, 240, 231, .55), rgba(255, 253, 248, .98));
}

.credentials-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.credentials-grid p {
  margin: 6px 0 0;
}

.filters-card h3 {
  margin-top: 0;
}

.filters-card {
  padding-bottom: 14px;
  background: linear-gradient(180deg, rgba(255, 253, 248, .98), rgba(250, 247, 239, .98));
}

.filters-inline select {
  min-width: 190px;
}

.compact-actions .solid-button,
.compact-actions .ghost-button {
  min-height: 38px;
  padding: 8px 12px;
}

.filter-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.placeholder-card {
  min-height: 220px;
  display: grid;
  align-content: start;
}

.finance-stats {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.search-box {
  min-width: 280px;
}

.note-line {
  margin-top: 10px;
}

.tax-groups {
  display: grid;
  gap: 22px;
}

.tax-group-card h3 {
  margin-top: 0;
}

.tax-group-card table {
  min-width: 0;
}

.region-bars {
  margin-top: 34px;
}

.page-intro+.stats-grid,
.page-intro+.justice-stats,
.page-intro+.card,
.page-intro+.filters-card {
  margin-top: 2px;
}

.form-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.full-width {
  grid-column: 1 / -1;
}

textarea {
  min-height: 120px;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 12px 14px;
  font: inherit;
  resize: vertical;
}

tbody tr:hover {
  background: rgba(15, 90, 70, 0.04);
}

thead th {
  color: #56766b;
  font-weight: 700;
}

/* Accordion Specifics for Notaries List */
details.application-row {
  transition: all 0.25s ease;
}

details.application-row[open] {
  background: var(--surface);
  border-left: 3px solid var(--accent);
}

details.application-row summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none;
  /* Hide default triangle */
  cursor: pointer;
  padding-right: 12px;
  /* Space for custom icon */
  position: relative;
}

details.application-row summary::-webkit-details-marker {
  display: none;
}

details.application-row summary::after {
  content: "▼";
  font-size: 0.85rem;
  color: var(--primary);
  transition: transform 0.25s ease;
}

details.application-row[open] summary::after {
  transform: rotate(180deg);
}

.accordion-content {
  padding-top: 15px;
  margin-top: 15px;
  border-top: 1px dashed var(--line);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

/* Audit Log Badges */
.badge {
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--line);
  color: #444;
}

.badge.login {
  background: #e3f2fd;
  color: #1976d2;
}

.badge.approve_application {
  background: #e8f5e9;
  color: #2e7d32;
}

.badge.renew_license {
  background: #fff3e0;
  color: #ef6c00;
}

.badge.reset_notary_password,
.badge.reset_staff_password {
  background: #fce4ec;
  color: #c2185b;
}

.badge.delete_staff {
  background: #ffebee;
  color: #c62828;
}

.user-cell {
  display: flex;
  flex-direction: column;
}

.user-cell strong {
  font-size: 0.95rem;
}

.small {
  font-size: 0.8rem;
}

@media (max-width: 960px) {

  .login-shell,
  .app-shell {
    grid-template-columns: 1fr;
  }

  .login-hero,
  .login-panel {
    padding: 32px 20px;
  }

  .topbar,
  .role-switcher,
  .item-row,
  .transaction-row,
  .application-row,
  .page-intro,
  .section-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .profile-copy {
    justify-items: start;
  }

  .search-box {
    min-width: 100%;
  }
}

.notification-toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: white;
  border-left: 5px solid var(--accent);
  padding: 16px 20px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 15px;
  z-index: 10000;
  transform: translateX(120%);
  transition: transform 0.5s cubic-bezier(0.19, 1, 0.22, 1);
  min-width: 320px;
  max-width: 400px;
}

.notification-toast.show {
  transform: translateX(0);
}

.toast-icon {
  font-size: 1.8rem;
}

.toast-content strong {
  display: block;
  font-size: 0.95rem;
  color: var(--text);
}

.toast-content p {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

/* Guarantee Letter Specific Styles - PREMIUM DESIGN MATCH */
.guarantee-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  align-items: start;
  margin-top: -10px;
}

.guarantee-form-card {
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 20px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.guarantee-preview-card {
  background: #f1f5f9;
  border: 1px solid var(--line);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  min-height: calc(100vh - 40px);
}

.preview-header {
  padding: 12px 20px;
  background: white;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.letter-scroll-area {
  padding: 40px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  justify-content: center;
  background: #cbd5e1; /* Darker background for contrast */
}

.official-letter {
  background: white;
  width: 210mm;
  min-height: 297mm;
  padding: 20mm;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  font-family: 'Inter', 'Segoe UI', sans-serif;
  color: #1e293b;
  position: relative;
}

/* Header Styles Matching Image */
.letter-header-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  text-align: center;
  margin-bottom: 10px;
}

.header-left { text-align: left; font-size: 0.85rem; font-weight: 700; line-height: 1.4; }
.header-right { text-align: right; font-size: 0.95rem; font-weight: 700; line-height: 1.4; }
.header-center { display: flex; flex-direction: column; align-items: center; }
.header-center img { width: 75px; height: 75px; margin-bottom: 5px; }

.ministry-title {
  font-size: 0.9rem;
  font-weight: 800;
  margin: 5px 0;
  color: #000;
}

.contact-bar {
  background: #0f5a46;
  color: white;
  padding: 6px 10px;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  margin: 15px 0;
  border-radius: 2px;
  -webkit-print-color-adjust: exact;
}

.letter-meta-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 2px double #000;
  padding-bottom: 5px;
  margin-bottom: 20px;
  font-weight: 800;
  font-size: 0.9rem;
}

.subject-box {
  background: #e2e8f0;
  border: 1.5px solid #64748b;
  padding: 10px;
  text-align: center;
  margin-bottom: 20px;
}

.subject-box h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 900;
  text-decoration: underline;
}

.letter-body-text {
  line-height: 1.8;
  font-size: 1.05rem;
  text-align: justify;
}

/* Fixed Table Layout */
.fixed-letter-table {
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  border-collapse: collapse;
  margin: 20px 0;
  table-layout: fixed;
}

.fixed-letter-table td {
  border: 1px solid #000;
  padding: 8px 12px;
  font-size: 0.95rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}

.fixed-letter-table td:first-child {
  background: #f1f5f9;
  font-weight: 800;
  width: 35%;
}

.sig-section {
  margin-top: 40px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.notary-cert-block {
  margin-top: 30px;
  border-top: 1px solid #ccc;
  padding-top: 15px;
  text-align: center;
}

/* Sidebar Icons Placeholder Box */
.sidebar-top-boxes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.status-box {
  border: 1px dashed var(--line);
  padding: 10px;
  border-radius: 8px;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
}

.status-box i {
  display: block;
  font-size: 1rem;
  margin-bottom: 4px;
}

/* Print Perfection */
@media print {
  @page { size: A4; margin: 0; }
  body { background: white !important; margin: 0 !important; padding: 0 !important; }
  .no-print, .guarantee-form-card, .preview-header, .sidebar, .topbar, .role-switcher, .app-shell > .sidebar { display: none !important; }
  .app-shell { display: block !important; }
  .main-shell, .content-grid { padding: 0 !important; margin: 0 !important; display: block !important; }
  .official-letter { 
    box-shadow: none !important; 
    margin: 0 !important; 
    padding: 10mm !important; 
    width: 210mm !important;
    border: none !important;
  }
}

@media (max-width: 1100px) {
  .guarantee-layout { grid-template-columns: 1fr; }
  .guarantee-form-card { position: static; max-height: none; }
}