@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@600;700&display=swap');

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

:root {
  --blue:        #1A3A5C;
  --mid-blue:    #2563EB;
  --light-blue:  #DBEAFE;
  --accent-blue: #BFDBFE;
  --dark-gray:   #111827;
  --gray:        #6B7280;
  --light-gray:  #F9FAFB;
  --white:       #FFFFFF;
  --green:       #16a34a;
  --red:         #dc2626;
  --yellow:      #d97706;
  --terracotta:  #C4632A;
  --forest:      #1A3D2B;
  --gold:        #D4A017;
  --cream:       #FAF7F2;
  --font:        'Inter', system-ui, sans-serif;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-sm:   0 1px 3px rgba(0,0,0,.06);
}

body {
  font-family: var(--font);
  color:       var(--dark-gray);
  background:  var(--cream);
  min-height:  100vh;
  font-size:   15px;
  line-height: 1.6;
}

/* ── App Header ──────────────────────────────────────────────────────────── */
.app-header {
  background:   var(--blue);
  color:        var(--white);
  padding:      0 28px;
  height:       60px;
  display:      flex;
  align-items:  center;
  gap:          16px;
  box-shadow:   0 2px 12px rgba(0,0,0,0.2);
  position:     sticky;
  top:          0;
  z-index:      100;
}
.app-header h1 {
  font-family:  'Playfair Display', serif;
  font-size:    18px;
  font-weight:  700;
  flex:         1;
  letter-spacing: 0.2px;
  color:        var(--white);
}
.app-header .role-badge {
  font-size:     11px;
  padding:       4px 12px;
  border-radius: 20px;
  background:    var(--terracotta);
  color:         var(--white);
  font-weight:   600;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.wallet-display {
  font-size:   12px;
  color:       rgba(255,255,255,0.65);
  font-family: monospace;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout {
  display:               grid;
  grid-template-columns: 220px 1fr;
  min-height:            calc(100vh - 60px);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--blue);
  padding:    20px 0;
  border-right: 1px solid rgba(255,255,255,0.06);
}
.sidebar nav a {
  display:         flex;
  align-items:     center;
  gap:             10px;
  color:           rgba(255,255,255,0.55);
  text-decoration: none;
  padding:         11px 22px;
  font-size:       14px;
  font-weight:     400;
  transition:      all 0.18s ease;
  border-left:     3px solid transparent;
}
.sidebar nav a:hover {
  background: rgba(255,255,255,0.07);
  color:      rgba(255,255,255,0.9);
}
.sidebar nav a.active {
  background:   rgba(196,99,42,0.15);
  color:        var(--white);
  font-weight:  600;
  border-left:  3px solid var(--terracotta);
}

/* ── Main ────────────────────────────────────────────────────────────────── */
.main { padding: 28px 32px; overflow-y: auto; }

/* ── Section ─────────────────────────────────────────────────────────────── */
.section { display: none; }
.section.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background:    var(--white);
  border-radius: var(--radius);
  box-shadow:    var(--shadow);
  padding:       22px 26px;
  margin-bottom: 22px;
  border:        1px solid rgba(0,0,0,0.05);
}
.card-title {
  font-family:    'Playfair Display', serif;
  font-size:      16px;
  font-weight:    600;
  color:          var(--blue);
  margin-bottom:  16px;
  padding-bottom: 12px;
  border-bottom:  2px solid var(--cream);
  display:        flex;
  align-items:    center;
  gap:            8px;
}
.card-title::before {
  content:      '';
  display:      inline-block;
  width:        3px;
  height:       16px;
  background:   var(--terracotta);
  border-radius: 2px;
  flex-shrink:  0;
}

/* ── Stat Grid ───────────────────────────────────────────────────────────── */
.stat-grid {
  display:               grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap:                   16px;
  margin-bottom:         24px;
}
.stat-card {
  background:    var(--white);
  border-radius: var(--radius);
  padding:       20px;
  text-align:    center;
  box-shadow:    var(--shadow-sm);
  border:        1px solid rgba(0,0,0,0.05);
  position:      relative;
  overflow:      hidden;
  transition:    transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card::after {
  content:    '';
  position:   absolute;
  bottom:     0; left: 0; right: 0;
  height:     3px;
  background: linear-gradient(90deg, var(--terracotta), var(--gold));
}
.stat-card .stat-number {
  font-family: 'Playfair Display', serif;
  font-size:   32px;
  font-weight: 700;
  color:       var(--blue);
  line-height: 1;
  margin-bottom: 6px;
}
.stat-card .stat-label {
  font-size:      11px;
  font-weight:    600;
  color:          var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-grid {
  display:               grid;
  grid-template-columns: 1fr 1fr;
  gap:                   16px;
}
.form-grid.single { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
  font-size:      12px;
  font-weight:    600;
  color:          var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-group input,
.form-group textarea,
.form-group select {
  padding:       10px 14px;
  border:        1.5px solid #E5E7EB;
  border-radius: var(--radius-sm);
  font-size:     14px;
  font-family:   var(--font);
  transition:    border-color 0.18s, box-shadow 0.18s;
  color:         var(--dark-gray);
  background:    var(--white);
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline:      none;
  border-color: var(--terracotta);
  box-shadow:   0 0 0 3px rgba(196,99,42,0.12);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-actions { margin-top: 20px; display: flex; gap: 10px; align-items: center; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  padding:       10px 22px;
  border:        none;
  border-radius: var(--radius-sm);
  font-size:     14px;
  font-weight:   500;
  cursor:        pointer;
  transition:    all 0.18s ease;
  font-family:   var(--font);
  display:       inline-flex;
  align-items:   center;
  gap:           6px;
  white-space:   nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background:  var(--terracotta);
  color:       var(--white);
  box-shadow:  0 2px 8px rgba(196,99,42,0.3);
}
.btn-primary:hover {
  background:  #A8511E;
  box-shadow:  0 4px 14px rgba(196,99,42,0.4);
}
.btn-secondary {
  background:  var(--white);
  color:       var(--blue);
  border:      1.5px solid #D1D5DB;
}
.btn-secondary:hover { background: var(--light-gray); border-color: var(--blue); }
.btn-danger    { background: var(--red); color: var(--white); }
.btn-danger:hover    { background: #b91c1c; }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table {
  width:           100%;
  border-collapse: collapse;
  font-size:       14px;
}
thead tr { background: var(--blue); }
thead th {
  padding:        11px 16px;
  text-align:     left;
  font-size:      11px;
  font-weight:    600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color:          rgba(255,255,255,0.85);
  white-space:    nowrap;
}
thead th:first-child { border-radius: 10px 0 0 0; }
thead th:last-child  { border-radius: 0 10px 0 0; }
tbody tr { border-bottom: 1px solid #F3F4F6; transition: background 0.12s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #FEF7F2; }
tbody td {
  padding:        11px 16px;
  color:          var(--dark-gray);
  vertical-align: middle;
}
tbody td.mono { font-family: monospace; font-size: 12px; color: var(--gray); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display:       inline-flex;
  align-items:   center;
  padding:       3px 10px;
  border-radius: 20px;
  font-size:     11px;
  font-weight:   600;
  letter-spacing: 0.3px;
}
.badge-green  { background: #D1FAE5; color: #065F46; }
.badge-red    { background: #FEE2E2; color: #991B1B; }
.badge-yellow { background: #FEF3C7; color: #92400E; }
.badge-blue   { background: var(--light-blue); color: var(--blue); }

/* ── Status message ──────────────────────────────────────────────────────── */
.status {
  font-size:     13px;
  font-weight:   500;
  padding:       9px 14px;
  border-radius: var(--radius-sm);
  margin-top:    10px;
  display:       none;
}
.status.info    { display: block; background: #EFF6FF; color: #1E40AF; border: 1px solid #BFDBFE; }
.status.success { display: block; background: #F0FDF4; color: #166534; border: 1px solid #BBF7D0; }
.status.error   { display: block; background: #FEF2F2; color: #991B1B; border: 1px solid #FECACA; }
.status.loading { display: block; background: #FFFBEB; color: #92400E; border: 1px solid #FDE68A; }

/* ── Timeline ────────────────────────────────────────────────────────────── */
.timeline { list-style: none; padding: 0; position: relative; }
.timeline::before {
  content:    '';
  position:   absolute;
  left:       14px; top: 0; bottom: 0;
  width:      2px;
  background: linear-gradient(to bottom, var(--terracotta), var(--light-blue));
}
.timeline li { position: relative; padding: 0 0 20px 40px; }
.timeline li::before {
  content:       '';
  position:      absolute;
  left:          7px; top: 4px;
  width:         14px; height: 14px;
  border-radius: 50%;
  background:    var(--terracotta);
  border:        2px solid var(--white);
  box-shadow:    0 0 0 2px var(--terracotta);
}
.timeline .tl-time   { font-size: 11px; color: var(--gray); margin-bottom: 2px; }
.timeline .tl-title  { font-weight: 600; font-size: 14px; color: var(--blue); }
.timeline .tl-detail { font-size: 13px; color: var(--gray); margin-top: 2px; }
.timeline .tl-hash   { font-size: 11px; color: var(--gray); font-family: monospace; margin-top: 4px; }

/* ── Connect screen ──────────────────────────────────────────────────────── */
.connect-screen {
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  min-height:      calc(100vh - 60px);
  gap:             16px;
  text-align:      center;
}
.connect-screen h2 { font-family: 'Playfair Display', serif; font-size: 22px; color: var(--blue); }
.connect-screen p  { color: var(--gray); font-size: 14px; max-width: 320px; line-height: 1.6; }

/* ── QR Reader ───────────────────────────────────────────────────────────── */
#reader { width: 300px; margin: 0 auto; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .main { padding: 16px; }
}

/* ── Mobile Header Fix ───────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .app-header {
    height: auto;
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .app-header h1 {
    font-size: 15px;
    width: 100%;
    flex: none;
  }
  .wallet-display { display: none; }
  .role-badge { font-size: 10px; padding: 3px 10px; }
  .main { padding: 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-card .stat-number { font-size: 26px; }
  .card { padding: 16px; }
  .connect-screen { min-height: calc(100vh - 80px); padding: 24px; }
  .connect-screen h2 { font-size: 20px; }
  .btn { padding: 10px 18px; }
}

/* ── Hamburger Button ────────────────────────────────────────────────────── */
.hamburger {
  display:        none;
  flex-direction: column;
  justify-content: center;
  gap:            5px;
  background:     transparent;
  border:         none;
  cursor:         pointer;
  padding:        4px;
  margin-left:    auto;
}
.hamburger span {
  display:       block;
  width:         22px;
  height:        2px;
  background:    var(--white);
  border-radius: 2px;
  transition:    all 0.2s ease;
}

/* ── Sidebar Overlay ─────────────────────────────────────────────────────── */
.sidebar-overlay {
  display:    none;
  position:   fixed;
  inset:      0;
  background: rgba(0,0,0,0.45);
  z-index:    199;
}
.sidebar-overlay.open { display: block; }

/* ── Sidebar Close Button ────────────────────────────────────────────────── */
.sidebar-close {
  display:     none;
  position:    absolute;
  top:         12px;
  right:       14px;
  background:  transparent;
  border:      none;
  color:       rgba(255,255,255,0.7);
  font-size:   24px;
  cursor:      pointer;
  line-height: 1;
}

/* ── Mobile Overrides ────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .hamburger { display: flex; }

  .sidebar {
    display:    block !important;
    position:   fixed;
    top:        0; left: 0;
    height:     100vh;
    width:      260px;
    z-index:    200;
    transform:  translateX(-100%);
    transition: transform 0.28s ease;
    padding-top: 52px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }

  .layout { grid-template-columns: 1fr; }
  .app-header {
    height:   auto;
    padding:  10px 16px;
    flex-wrap: wrap;
    gap:      8px;
  }
  .app-header h1   { font-size: 15px; flex: 1; width: auto; }
  .wallet-display  { display: none; }
  .role-badge      { font-size: 10px; padding: 3px 10px; }
  .main            { padding: 16px; }
  .stat-grid       { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-card .stat-number { font-size: 26px; }
  .card            { padding: 16px; }
  .connect-screen  { min-height: calc(100vh - 80px); padding: 24px; }
  .connect-screen h2 { font-size: 20px; }
}

/* ── Loading spinner ─────────────────────────────────────────────────────── */
.status.loading::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid #FCD34D;
  border-top-color: #92400E;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
