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

:root {
  --bg: #f5f6fa;
  --surface: #fff;
  --surface2: #f8f8fc;
  --border: #e0e0eb;
  --border-light: #f0f0f5;
  --text: #1a1a2e;
  --text2: #555;
  --text3: #888;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-light: #f0efff;
  --accent-border: #c7d2fe;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --success: #16a34a;
  --success-light: #dcfce7;
  --success-text: #166534;
  --success-border: #86efac;
  --warning-light: #fffbeb;
  --warning-text: #92400e;
  --warning-bg: #fef3c7;
  --input-bg: #fafafa;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
}

html.dark {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface2: #23232f;
  --border: #2e2e3e;
  --border-light: #252530;
  --text: #e8e8f0;
  --text2: #9999bb;
  --text3: #666688;
  --accent: #6366f1;
  --accent-hover: #7c7ff5;
  --accent-light: #1e1e35;
  --accent-border: #4a4a8a;
  --danger: #f87171;
  --danger-light: #2d1414;
  --success: #4ade80;
  --success-light: #14291a;
  --success-text: #4ade80;
  --success-border: #166534;
  --warning-light: #2a200a;
  --warning-text: #fbbf24;
  --warning-bg: #2d2010;
  --input-bg: #23232f;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.2);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
       background: var(--bg); color: var(--text); transition: background .2s, color .2s; }

header { background: var(--surface); border-bottom: 1px solid var(--border);
         padding: 0 24px; height: 56px; display: flex;
         align-items: center; justify-content: space-between; }
.logo { font-size: 20px; font-weight: 700; color: var(--accent); letter-spacing: -0.5px; }
nav a { color: var(--text2); text-decoration: none; font-size: 14px; }
nav a:hover { color: var(--accent); }
#nav-email { color: var(--text3) !important; }

.container { max-width: 720px; margin: 0 auto; padding: 32px 16px; }

.hero { text-align: center; margin-bottom: 32px; }
.hero h1 { font-size: 28px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.hero p { color: var(--text2); font-size: 16px; }

.card { background: var(--surface); border-radius: 12px; padding: 32px;
        box-shadow: var(--shadow); }
.card.success { text-align: center; }

.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase;
                 letter-spacing: 1px; color: var(--text3); margin: 24px 0 12px; }
.section-title:first-of-type { margin-top: 0; }
.optional { font-weight: 400; text-transform: none; letter-spacing: 0; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.field { margin-bottom: 4px; }
.field label { display: block; font-size: 13px; font-weight: 500;
               color: var(--text2); margin-bottom: 6px; }
.field input, .field textarea, .field-select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; color: var(--text);
  transition: border-color .15s; background: var(--input-bg); }
.field input:focus, .field textarea:focus, .field-select:focus {
  outline: none; border-color: var(--accent); background: var(--surface); }
.field textarea { resize: vertical; }
.field-select { cursor: pointer; }

.btn-primary { display: inline-block; background: var(--accent); color: #fff;
               border: none; border-radius: 8px; padding: 12px 28px;
               font-size: 15px; font-weight: 600; cursor: pointer;
               margin-top: 24px; width: 100%; transition: background .15s; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-secondary { display: inline-block; background: var(--surface); color: var(--accent);
                 border: 2px solid var(--accent); border-radius: 8px;
                 padding: 10px 24px; font-size: 14px; font-weight: 600;
                 text-decoration: none; cursor: pointer; transition: all .15s; }
.btn-secondary:hover { background: var(--accent-light); }

.btn-link { background: none; border: none; color: var(--accent); cursor: pointer;
            font-size: 14px; margin-top: 12px; text-decoration: underline; }

.btn-small { font-size: 12px; padding: 4px 10px; border: 1px solid var(--accent);
             color: var(--accent); border-radius: 6px; text-decoration: none;
             margin-right: 4px; }
.btn-small:hover { background: var(--accent-light); }

.error { color: var(--danger); font-size: 13px; margin-top: 8px; }

.check { font-size: 48px; margin-bottom: 16px; }
.card.success h2 { font-size: 22px; margin-bottom: 8px; }
.card.success p { color: var(--text2); }

.page-title { font-size: 24px; font-weight: 700; margin-bottom: 24px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface);
        border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-sm); }
thead th { background: var(--surface2); padding: 12px 16px; text-align: left;
           font-size: 12px; font-weight: 600; text-transform: uppercase;
           letter-spacing: .5px; color: var(--text3); }
tbody td { padding: 14px 16px; border-top: 1px solid var(--border-light);
           font-size: 14px; }
tbody td small { color: var(--text3); font-size: 12px; }

.badge { padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-signed  { background: var(--success-light); color: var(--success-text); }
.badge-pending { background: var(--warning-bg); color: var(--warning-text); }
.badge-green   { background: var(--success-light); color: var(--success-text); }
.badge-blue    { background: var(--accent-light); color: var(--accent); }
.badge-yellow  { background: var(--warning-bg); color: var(--warning-text); }

.empty { text-align: center; padding: 60px 0; color: var(--text3); }
.empty p { margin-bottom: 20px; }

.summary { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.summary td { padding: 8px 0; border-bottom: 1px solid var(--border-light); font-size: 14px; word-break: break-word; }
.summary td:first-child { font-weight: 600; color: var(--text2); width: 40%; }

.rules-block { background: var(--surface2); border-left: 3px solid var(--accent);
               padding: 12px 16px; border-radius: 4px; margin: 16px 0; }
.rules-block strong { font-size: 13px; }
.rules-block p { font-size: 13px; color: var(--text2); margin-top: 6px; }

.sign-instruction { font-size: 13px; color: var(--warning-text); margin: 20px 0 12px;
                    padding: 12px; background: var(--warning-light); border-radius: 8px; }
.sign-hint { font-size: 13px; color: var(--text3); margin: 0 0 8px; padding: 8px 10px;
             background: var(--surface2); border-radius: 6px; border-left: 3px solid var(--accent-border); }

.contract-type-selector { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.type-option { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border: 2px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 14px; transition: all .15s; color: var(--text); }
.type-option.selected { border-color: var(--accent); background: var(--accent-light); color: var(--accent); font-weight: 600; }
.type-option input[type=radio] { display: none; }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab { padding: 8px 18px; border: 2px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; font-size: 14px; font-weight: 500; color: var(--text2); transition: all .15s; }
.tab.active { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.tab:hover:not(.active) { border-color: var(--text3); }

.template-editor { width: 100%; font-family: 'Courier New', monospace; font-size: 13px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; resize: vertical; line-height: 1.5; background: var(--input-bg); color: var(--text); margin-top: 16px; }
.template-editor:focus { outline: none; border-color: var(--accent); background: var(--surface); }

.placeholders-ref { background: var(--surface2); border-radius: 8px; padding: 12px 16px; margin-bottom: 4px; font-size: 13px; }
.placeholders-ref code { background: var(--accent-light); color: var(--accent); padding: 2px 6px; border-radius: 4px; font-size: 12px; margin: 2px; display: inline-block; }

.tmpl-actions { display: flex; gap: 12px; align-items: center; margin-top: 12px; }
.btn-reset { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 10px 18px; font-size: 14px; cursor: pointer; color: var(--text2); }
.btn-reset:hover { border-color: var(--danger); color: var(--danger); }
.save-ok { color: var(--success); font-size: 13px; margin-top: 8px; }

.link-box { display: flex; align-items: center; gap: 8px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 16px 0; text-align: left; }
.link-box span { flex: 1; font-size: 13px; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 0 0 12px; }
.btn-tg { background: #0088cc; color: #fff; border: none; border-radius: 8px; padding: 10px 20px; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block; }
.btn-wa { background: #25d366; color: #fff; border: none; border-radius: 8px; padding: 10px 20px; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block; }

.pass-wrap { position: relative; }
.pass-wrap input { width: 100%; padding-right: 40px; }
.pass-eye { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; font-size: 16px; line-height: 1; padding: 0; }

.agreement-card { background: var(--surface); border-radius: 12px; padding: 20px 24px; margin-bottom: 12px; box-shadow: var(--shadow); }
.agreement-main { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.agreement-info { flex: 1; }
.agreement-guest { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.agreement-meta { font-size: 13px; color: var(--text2); margin-bottom: 4px; }
.agreement-passport-data { font-size: 12px; color: var(--text3); margin-top: 4px; }
.agreement-actions { display: flex; gap: 6px; flex-shrink: 0; }
.passport-thumbs { display: flex; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border-light); }
.passport-thumb { display: flex; flex-direction: column; align-items: center; gap: 4px; text-decoration: none; }
.passport-thumb img { width: 120px; height: 80px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.passport-thumb span { font-size: 11px; color: var(--text3); }

.passport-label-text { font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.passport-col { display: flex; flex-direction: column; }
.passport-upload-wrap { margin-top: auto; }
.passport-upload { display: flex; align-items: center; justify-content: center; min-height: 100px; border: 2px dashed var(--accent-border); border-radius: 10px; background: var(--accent-light); padding: 12px; text-align: center; cursor: pointer; transition: background .15s; font-size: 13px; color: var(--accent); }
.passport-upload:hover { opacity: .85; }
.passport-upload.loaded { border-color: var(--success-border); background: var(--success-light); }

.canvas-wrap { border: 2px dashed var(--border); border-radius: 8px; background: var(--surface2); margin: 0 0 16px; position: relative; overflow: hidden; }
.canvas-wrap canvas { display: block; width: 100%; height: 160px; border-radius: 6px; cursor: crosshair; touch-action: none; }
.canvas-clear { position: absolute; top: 8px; right: 10px; margin: 0; padding: 2px 8px; font-size: 12px; color: var(--text3); text-decoration: none; }
.canvas-clear:hover { color: var(--danger); }

/* Theme toggle button */
.theme-toggle { background: var(--surface2); border: 1px solid var(--border); border-radius: 20px; padding: 4px 10px; cursor: pointer; font-size: 15px; line-height: 1; margin-left: 12px; transition: all .15s; }
.theme-toggle:hover { border-color: var(--accent); }

/* Dark mode override for inline colors */
html.dark [style*="color:#888"], html.dark [style*="color: #888"] { color: var(--text3) !important; }
html.dark [style*="color:#666"], html.dark [style*="color: #666"] { color: var(--text2) !important; }
html.dark [style*="color:#555"], html.dark [style*="color: #555"] { color: var(--text2) !important; }
html.dark [style*="background:#fff"], html.dark [style*="background: #fff"] { background: var(--surface) !important; }
html.dark [style*="background:#f8f8fc"], html.dark [style*="background: #f8f8fc"] { background: var(--surface2) !important; }

@media (max-width: 600px) {
  .container { padding: 12px 12px; }
  .card { padding: 16px 14px; }
  .row2 { grid-template-columns: 1fr; gap: 12px; }
  .canvas-wrap canvas { height: 130px; }
  .passport-upload { min-height: 80px; }
  .hero h1 { font-size: 22px; }
  .page-title { font-size: 20px; margin-bottom: 16px; }
  .summary td { font-size: 13px; }
  .summary td:first-child { width: 36%; }
  .btn-primary { margin-top: 16px; }
  .sign-instruction { margin: 12px 0 8px; font-size: 13px; }
  .agreement-main { flex-direction: column; gap: 10px; }
  .agreement-actions { justify-content: flex-start; }
  .passport-thumbs { flex-wrap: wrap; gap: 8px; }
  .passport-thumb img { width: 96px; height: 64px; }
  .tabs { flex-wrap: wrap; gap: 6px; }
  .tmpl-actions { flex-wrap: wrap; }
  .share-btns { flex-direction: column; align-items: stretch; }
  .share-btns a, .share-btns button { text-align: center; }
  .btn-secondary { width: 100% !important; text-align: center; display: block !important; box-sizing: border-box; }
  .theme-toggle { padding: 4px 8px; font-size: 13px; }
}

/* ── Chat widget ──────────────────────────────────────────────────────────── */
.chat-fab { position:fixed; bottom:24px; right:24px; top:auto; left:auto; width:56px; height:56px; border-radius:50%; background:var(--accent); border:none; cursor:pointer; box-shadow:0 4px 20px rgba(0,0,0,.25); display:flex; align-items:center; justify-content:center; z-index:9999; flex-shrink:0; transition:transform .15s; }
.chat-fab:hover { transform:scale(1.08); }
.chat-window { position:fixed; bottom:88px; right:24px; width:340px; height:480px; background:var(--surface); border-radius:16px; box-shadow:0 8px 40px rgba(0,0,0,.18); display:flex; flex-direction:column; z-index:1000; border:1px solid var(--border); overflow:hidden; transition:opacity .2s, transform .2s; }
.chat-window.hidden { opacity:0; pointer-events:none; transform:translateY(12px); }
.chat-header { padding:14px 16px; background:var(--accent); color:#fff; font-weight:600; font-size:14px; display:flex; justify-content:space-between; align-items:center; flex-shrink:0; }
.chat-close { background:none; border:none; color:rgba(255,255,255,.8); cursor:pointer; font-size:18px; line-height:1; padding:0; }
.chat-close:hover { color:#fff; }
.chat-messages { flex:1; overflow-y:auto; padding:14px; display:flex; flex-direction:column; gap:10px; }
.chat-msg { max-width:86%; padding:10px 13px; border-radius:12px; font-size:13px; line-height:1.5; word-break:break-word; }
.chat-msg.user { background:var(--accent); color:#fff; align-self:flex-end; border-bottom-right-radius:4px; }
.chat-msg.bot { background:var(--bg); color:var(--text); align-self:flex-start; border-bottom-left-radius:4px; border:1px solid var(--border); }
.chat-input-row { display:flex; gap:8px; padding:10px 12px; border-top:1px solid var(--border); flex-shrink:0; }
.chat-input { flex:1; padding:9px 12px; border:1px solid var(--border); border-radius:8px; background:var(--bg); color:var(--text); font-size:13px; outline:none; font-family:inherit; }
.chat-input:focus { border-color:var(--accent); }
.chat-send { padding:9px 14px; background:var(--accent); color:#fff; border:none; border-radius:8px; cursor:pointer; font-size:16px; line-height:1; }
.chat-send:disabled { opacity:.4; cursor:default; }
@media (max-width:400px) { .chat-window { right:8px; left:8px; width:auto; bottom:80px; } }
