/* ============================================================
   Zer Elektronik — Global Stylesheet
   ============================================================ */

/* Google Fonts loaded via <link> in HTML to avoid @import waterfall */

:root {
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;
  --bg:         #f5f0eb;
  --card:       #ffffff;
  --accent:     #ff6b35;
  --accent-hover:#e85a28;
  --text:       #2a2a3d;
  --text-secondary: #5a5a6e;
  --muted:      #7a7a8e;
  --border:     #e8e0d8;
  --green:      #30a060;
  --green-light:#e8f5e9;
  --red:        #e04040;
  --red-light:  #fdeaea;
  --blue:       #3b82f6;
  --blue-light: #eff6ff;
  --orange:     #f59e0b;
  --orange-light:#fff8e1;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.06);
  --shadow-md:  0 4px 12px rgba(0,0,0,.08);
  --shadow-lg:  0 8px 30px rgba(0,0,0,.10);
  --radius:     10px;
  --radius-sm:  6px;
  --radius-lg:  14px;
  --transition: .2s ease;
  --table-hover: #faf7f4;
  --table-head:  #faf7f4;
  --sidebar-bg:  #2a2a3d;
}

[data-theme="dark"] {
  --bg:         #1a1a2e;
  --card:       #242440;
  --text:       #e8e8f0;
  --text-secondary: #a0a0b8;
  --muted:      #6e6e88;
  --border:     #3a3a55;
  --green-light:#1a3a28;
  --red-light:  #3a1a1a;
  --blue-light: #1a2640;
  --orange-light:#2e2810;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.2);
  --shadow-md:  0 4px 12px rgba(0,0,0,.3);
  --shadow-lg:  0 8px 30px rgba(0,0,0,.4);
  --table-hover: #2a2a48;
  --table-head:  #2e2e4a;
  --sidebar-bg:  #16162a;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; display: block; }

/* --- Typography --- */
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.35rem; font-weight: 600; letter-spacing: -0.01em; }
h3 { font-size: 1.1rem;  font-weight: 600; }
h4 { font-size: 0.95rem; font-weight: 600; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.text-center { text-align: center; }

/* --- Layout --- */
.container { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 1.5rem; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-xs { gap: 0.35rem; }
.gap-sm { gap: 0.6rem; }
.gap-md { gap: 1rem; }
.gap-lg { gap: 1.5rem; }
.gap-xl { gap: 2rem; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* --- Card --- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.card-lg { padding: 2rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.6rem 1.2rem; font-family: var(--font-body); font-size: 0.9rem; font-weight: 500;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap; line-height: 1.4;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); box-shadow: 0 2px 8px rgba(255,107,53,.3); }
.btn-secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); border-color: var(--muted); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #c83030; }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover:not(:disabled) { background: #278a50; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 1.6rem; font-size: 1rem; font-weight: 600; }
.btn-block { width: 100%; }

/* --- Forms --- */
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-label { font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); }

.form-input,
.form-textarea {
  width: 100%; padding: 0.6rem 0.85rem; font-family: var(--font-body); font-size: 0.9rem;
  color: var(--text); background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); transition: border-color var(--transition), box-shadow var(--transition); outline: none;
}

/* --- Native Select --- */
.form-select {
  width: 100%; padding: 0.6rem 2.2rem 0.6rem 0.85rem;
  font-family: var(--font-body); font-size: 0.9rem; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition); outline: none; cursor: pointer;
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237a7a8e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.7rem center; background-size: 16px;
}
.form-select:invalid, .form-select option[value=""] { color: var(--muted); }
.form-select option { color: var(--text); padding: 0.4rem; }
.form-select-sm { padding: 0.3rem 1.8rem 0.3rem 0.5rem; font-size: 0.82rem; background-size: 14px; background-position: right 0.4rem center; }

/* --- Combo Select (searchable dropdown) --- */
.combo-select { position: relative; width: 100%; }
.combo-select-input {
  width: 100%; padding: 0.6rem 2.2rem 0.6rem 0.85rem;
  font-family: var(--font-body); font-size: 0.9rem; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  outline: none; cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237a7a8e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.7rem center; background-size: 16px;
}
.combo-select-input::placeholder { color: var(--muted); }
.combo-select-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,107,53,.12); cursor: text; }
.combo-select.error .combo-select-input { border-color: var(--red); box-shadow: 0 0 0 3px rgba(224,64,64,.1); }
.combo-select-dropdown {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); max-height: 200px; overflow-y: auto; z-index: 50;
}
.combo-select.open .combo-select-dropdown { display: block; }
.combo-select-option {
  padding: 0.5rem 0.85rem; font-size: 0.9rem; color: var(--text); cursor: pointer;
  transition: background var(--transition);
}
.combo-select-option:hover, .combo-select-option.highlighted { background: var(--table-hover); }
.combo-select-option.selected { color: var(--accent); font-weight: 500; }
.combo-select-empty { padding: 0.5rem 0.85rem; font-size: 0.85rem; color: var(--muted); font-style: italic; }
.combo-select-sm .combo-select-input { padding: 0.3rem 1.8rem 0.3rem 0.5rem; font-size: 0.82rem; background-size: 14px; background-position: right 0.4rem center; }
.combo-select-sm .combo-select-option { padding: 0.35rem 0.5rem; font-size: 0.82rem; }

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,107,53,.12);
}
.form-input::placeholder { color: var(--muted); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-input.error, .form-select.error { border-color: var(--red); box-shadow: 0 0 0 3px rgba(224,64,64,.1); }
.form-error { font-size: 0.78rem; color: var(--red); min-height: 1.2em; }
.form-hint { font-size: 0.78rem; color: var(--muted); }

/* --- Input Group (email suffix etc.) --- */
.input-group {
  display: flex; align-items: stretch; border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-group:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,107,53,.12); }
.input-group .form-input { border: none; border-radius: 0; box-shadow: none; }
.input-group .form-input:focus { box-shadow: none; }
.input-group-suffix {
  display: flex; align-items: center; padding: 0 0.75rem;
  background: var(--bg); color: var(--muted); font-size: 0.82rem; font-weight: 500;
  white-space: nowrap; border-left: 1px solid var(--border); user-select: none;
}
.input-group.error { border-color: var(--red); box-shadow: 0 0 0 3px rgba(224,64,64,.1); }

/* --- Badges --- */
.badge {
  display: inline-flex; align-items: center; padding: 0.2rem 0.6rem;
  font-size: 0.72rem; font-weight: 600; border-radius: 99px;
  letter-spacing: 0.02em; text-transform: uppercase;
}
.badge-green  { background: var(--green-light); color: var(--green); }
.badge-red    { background: var(--red-light);   color: var(--red); }
.badge-blue   { background: var(--blue-light);  color: var(--blue); }
.badge-orange { background: var(--orange-light); color: var(--orange); }
.badge-purple { background: rgba(139,92,246,0.12); color: #8b5cf6; }
.badge-muted  { background: #f0ece8; color: var(--muted); }

/* --- Tables --- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
thead { background: var(--table-head); position: sticky; top: 0; z-index: 1; }
th {
  text-align: left; padding: 0.65rem 0.85rem; font-weight: 600; font-size: 0.78rem;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 2px solid var(--border); white-space: nowrap;
}
td { padding: 0.6rem 0.85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--table-hover); }
tbody tr:last-child td { border-bottom: none; }

/* --- Alerts / Toasts --- */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius-sm); font-size: 0.88rem; font-weight: 500; }
.alert-error   { background: var(--red-light);    color: var(--red); }
.alert-success { background: var(--green-light);  color: var(--green); }
.alert-info    { background: var(--blue-light);   color: var(--blue); }
.alert-warning { background: var(--orange-light); color: var(--orange); }

.toast-container {
  position: fixed; top: 1.5rem; right: 1.5rem; z-index: 9999;
  display: flex; flex-direction: column; gap: 0.5rem; pointer-events: none;
}
.toast {
  padding: 0.7rem 1.2rem; border-radius: var(--radius-sm);
  font-size: 0.88rem; font-weight: 500; box-shadow: var(--shadow-md);
  pointer-events: auto; animation: toast-in 0.3s ease forwards; max-width: 360px;
}
.toast.out { animation: toast-out 0.25s ease forwards; }
@keyframes toast-in  { from { opacity:0; transform:translateX(30px); } to { opacity:1; transform:translateX(0); } }
@keyframes toast-out { from { opacity:1; transform:translateX(0); } to { opacity:0; transform:translateX(30px); } }

/* --- Overlay / Modal --- */
.overlay {
  position: fixed; inset: 0; background: rgba(42,42,61,.55);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center; animation: fade-in 0.2s ease;
}
.modal {
  background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 90%; max-width: 560px; max-height: 85vh; overflow-y: auto; padding: 2rem;
  animation: slide-up 0.25s ease;
}
@keyframes fade-in { from { opacity:0; } to { opacity:1; } }
@keyframes slide-up { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }

/* --- Sidebar --- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--sidebar-bg); color: #fff;
  display: flex; flex-direction: column; flex-shrink: 0;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; overflow-y: auto;
}
.sidebar-brand {
  padding: 1.3rem 1.2rem; font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em;
  border-bottom: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: 0.5rem;
}
.sidebar-brand .accent { color: var(--accent); }
.sidebar-section {
  padding: 0.6rem 0.8rem 0.3rem; font-size: 0.68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em; color: rgba(255,255,255,.35);
}
.sidebar-subsection {
  padding: 0.4rem 1.2rem 0.2rem; font-size: 0.62rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.06em; color: rgba(255,255,255,.25);
  margin-top: 0.3rem;
}
.sidebar-link {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 1.2rem;
  font-size: 0.88rem; color: rgba(255,255,255,.65);
  transition: background var(--transition), color var(--transition); text-decoration: none;
}
.sidebar-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-link.active { background: rgba(255,107,53,.15); color: var(--accent); font-weight: 500; }
.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.sidebar-link.active svg { opacity: 1; }
.sidebar-footer {
  margin-top: auto; padding: 1rem 1.2rem; border-top: 1px solid rgba(255,255,255,.08);
  font-size: 0.82rem; color: rgba(255,255,255,.45);
}
.sidebar-footer .user-name { color: rgba(255,255,255,.85); font-weight: 500; }
.sidebar-footer .user-dept { font-size: 0.72rem; color: rgba(255,255,255,.4); }
.sidebar-logout {
  margin-top: 0; background: none; border: none; color: rgba(255,255,255,.4);
  font-family: var(--font-body); font-size: 0.8rem; cursor: pointer; padding: 0.3rem 0;
  transition: color var(--transition);
}
.sidebar-logout:hover { color: var(--red); }

.sidebar-home-link {
  display: flex; align-items: center; gap: 0.6rem;
  margin-top: 0.7rem; padding: 0.5rem 0.6rem;
  border-radius: 8px; border: 1px solid rgba(255,255,255,.08);
  text-decoration: none; color: rgba(255,255,255,.5);
  font-size: 0.75rem; font-weight: 500;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.sidebar-home-link:hover {
  background: rgba(255,255,255,.05); color: rgba(255,255,255,.85);
  border-color: rgba(255,255,255,.15);
}
.sidebar-home-logo {
  height: 22px; width: auto; object-fit: contain;
  filter: invert(1); opacity: 0.6; transition: opacity 0.2s;
}
.sidebar-home-link:hover .sidebar-home-logo { opacity: 1; }

/* --- Main Content --- */
.main-content { flex: 1; margin-left: 240px; padding: 2rem; min-height: 100vh; }
.page-header { margin-bottom: 1.5rem; }
.page-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.page-subtitle { font-size: 0.9rem; color: var(--muted); margin-top: 0.25rem; }

/* --- Auth Pages --- */
.auth-page {
  min-height: 100vh; display: flex; align-items: center;
  justify-content: center; background: var(--bg); padding: 1.5rem;
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--card);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 2.5rem 2rem;
}
.auth-logo { text-align: center; margin-bottom: 1.8rem; }
.auth-logo h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.auth-logo .accent { color: var(--accent); }
.auth-logo p { font-size: 0.85rem; color: var(--muted); margin-top: 0.3rem; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-footer { text-align: center; margin-top: 1.5rem; font-size: 0.85rem; color: var(--muted); }
.auth-footer a { font-weight: 500; }

/* --- Spinner --- */
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.3); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
.spinner-dark { border-color: rgba(0,0,0,.1); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Empty State --- */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state svg { margin-bottom: 1rem; opacity: 0.4; }
.empty-state p { font-size: 0.95rem; }

/* --- Theme Toggle --- */
.theme-toggle { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; user-select: none; }
.theme-toggle-track {
  width: 36px; height: 20px; background: rgba(255,255,255,.15);
  border-radius: 99px; position: relative; transition: background var(--transition);
}
.theme-toggle-thumb {
  width: 16px; height: 16px; background: #fff; border-radius: 50%;
  position: absolute; top: 2px; left: 2px; transition: transform var(--transition);
}
[data-theme="dark"] .theme-toggle-track { background: var(--accent); }
[data-theme="dark"] .theme-toggle-thumb { transform: translateX(16px); }
.theme-toggle-label { font-size: 0.75rem; color: rgba(255,255,255,.45); }
.auth-theme-toggle {
  position: fixed; top: 1.2rem; right: 1.2rem; z-index: 10;
  display: flex; align-items: center; gap: 0.4rem; cursor: pointer;
}
.auth-theme-toggle .theme-toggle-label { color: var(--muted); }

/* --- Dark mode overrides --- */
[data-theme="dark"] .form-select,
[data-theme="dark"] .combo-select-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236e6e88' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
[data-theme="dark"] .badge-muted { background: #2e2e4a; }
[data-theme="dark"] .overlay { background: rgba(10,10,20,.7); }

/* --- Responsive --- */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-brand span, .sidebar-section, .sidebar-subsection, .sidebar-link span,
  .sidebar-footer .user-name, .sidebar-footer .user-dept, .theme-toggle-label { display: none; }
  .sidebar-link { justify-content: center; padding: 0.7rem; }
  .main-content { margin-left: 60px; padding: 1rem; }
}

/* ============================================================
   Contract Signing Overlay
   ============================================================ */
.cs-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: var(--bg); display: flex; flex-direction: column;
}
.cs-modal {
  display: flex; flex-direction: column; height: 100vh; width: 100%;
  max-width: 900px; margin: 0 auto; background: var(--bg);
}
.cs-header {
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--border);
  background: var(--card); flex-shrink: 0;
}
.cs-progress { display: flex; align-items: center; flex-wrap: wrap; gap: 0.25rem; }
.cs-progress-bar {
  margin-top: 0.5rem; height: 4px; background: var(--border);
  border-radius: 2px; overflow: hidden;
}
.cs-progress-fill {
  height: 100%; background: var(--accent); border-radius: 2px;
  transition: width .3s ease;
}
.cs-body {
  flex: 1; overflow-y: auto; padding: 1.5rem;
}
.cs-content {
  background: var(--card); border-radius: var(--radius);
  padding: 2rem; box-shadow: var(--shadow-sm);
  line-height: 1.8; font-size: 0.95rem;
}
.cs-content h1 { font-size: 1.3rem; margin: 1.5rem 0 0.75rem; }
.cs-content h2 { font-size: 1.15rem; margin: 1.25rem 0 0.5rem; }
.cs-content h3 { font-size: 1.05rem; margin: 1rem 0 0.5rem; }
.cs-content ul, .cs-content ol { padding-left: 1.5rem; margin: 0.5rem 0; }
.cs-content li { margin-bottom: 0.3rem; }
.cs-content hr { border: none; border-top: 2px solid var(--border); margin: 2rem 0; }
.cs-content strong { font-weight: 600; }
.cs-content em { font-style: italic; }
.cs-footer {
  padding: 1rem 1.5rem; border-top: 1px solid var(--border);
  background: var(--card); flex-shrink: 0;
  display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
}
.cs-sig-section { flex: 1; min-width: 280px; }
.cs-canvas-wrap {
  margin-top: 0.5rem; border: 2px dashed var(--border);
  border-radius: var(--radius-sm); background: #fff; cursor: crosshair;
}
[data-theme="dark"] .cs-canvas-wrap { background: #1e1e36; }
.cs-canvas-wrap canvas { display: block; width: 100%; touch-action: none; }
.cs-sign-btn { white-space: nowrap; align-self: flex-end; }

/* --- Token multi-select chips --- */
.token-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.35rem; }
.token-chip {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.2rem 0.6rem; border-radius: 20px; font-size: 0.8rem;
  background: var(--blue-light); color: var(--blue); cursor: pointer;
  border: 1px solid transparent; transition: var(--transition);
}
.token-chip.selected { background: var(--blue); color: #fff; }
.token-chip:hover { border-color: var(--blue); }