*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #1a1a2e; --surface: #16213e; --surface2: #0f3460;
  --surface-light: #1e2a4a; --border: #2a3a5c; --text: #e8e8f0;
  --muted: #8892b0; --accent: #e94560; --accent2: #ff6b6b;
  --accent-glow: rgba(233,69,96,0.3); --green: #00d2d3; --green-bg: rgba(0,210,211,0.1);
  --radius: 12px; --font: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --mono: 'Courier New', monospace; --shadow: 0 4px 24px rgba(0,0,0,0.3);
}
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }

/* ── HEADER ── */
.header { background: linear-gradient(135deg, #16213e 0%, #1a1a2e 100%); border-bottom: 1px solid var(--border); padding: 16px 32px; display: flex; align-items: center; justify-content: space-between; }
.header-left { display: flex; align-items: center; gap: 14px; }
.header-logo { width: 40px; height: 40px; background: linear-gradient(135deg, var(--accent), var(--accent2)); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; color: #fff; font-weight: 700; }
.header h1 { font-size: 20px; font-weight: 700; color: #fff; letter-spacing: -0.5px; }
.header p { font-size: 12px; color: var(--muted); margin-top: 2px; }
.header-actions { display: flex; gap: 10px; }
.header-btn { padding: 8px 18px; font-size: 13px; font-weight: 600; border: 1.5px solid var(--border); border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; transition: all .2s; font-family: var(--font); }
.header-btn:hover { border-color: var(--accent); color: var(--accent); }
.header-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.header-btn.primary:hover { background: var(--accent2); border-color: var(--accent2); box-shadow: 0 0 20px var(--accent-glow); }

/* ── TABS ── */
.tabs-container { max-width: 1100px; margin: 24px auto 0; padding: 0 24px; }
.tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.tab-btn { padding: 10px 28px; font-size: 13px; font-weight: 600; border: none; background: transparent; cursor: pointer; color: var(--muted); transition: all .2s; font-family: var(--font); position: relative; }
.tab-btn.active { color: #fff; background: var(--accent); }
.tab-btn:hover:not(.active) { color: var(--text); background: var(--surface-light); }

/* ── LAYOUT ── */
.main-content { max-width: 1100px; margin: 20px auto; padding: 0 24px 48px; }
.layout { display: grid; grid-template-columns: 320px 1fr; gap: 24px; align-items: start; }

/* ── CARDS ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; transition: border-color .2s; }
.card:hover { border-color: rgba(233,69,96,0.3); }
.card-title { font-size: 14px; font-weight: 700; color: #fff; margin-bottom: 4px; }
.card-subtitle { font-size: 12px; color: var(--muted); margin-bottom: 16px; }

/* ── FORM FIELDS ── */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
input[type=text], input[type=number], input[type=date], select {
  width: 100%; padding: 10px 14px; font-size: 13px; font-family: var(--font);
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-light);
  color: var(--text); outline: none; transition: all .2s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); background: var(--surface); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%238892b0' fill='none' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; cursor: pointer; }
select option { background: var(--surface); color: var(--text); }

/* ── AMOUNT ROW ── */
.amount-row { display: flex; gap: 10px; align-items: flex-end; }
.amount-row .field { flex: 1; margin-bottom: 0; }
.amount-check { width: 38px; height: 38px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-light); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all .2s; flex-shrink: 0; }
.amount-check:hover { border-color: var(--accent); }
.amount-check.active { background: var(--accent); border-color: var(--accent); }
.amount-check svg { width: 16px; height: 16px; stroke: var(--muted); }
.amount-check.active svg { stroke: #fff; }

/* ── TOGGLE SWITCH ── */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }
.toggle-row .toggle-label { font-size: 13px; font-weight: 500; color: var(--text); }
.toggle-row .toggle-sublabel { font-size: 11px; color: var(--muted); margin-top: 2px; }
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { display: none; }
.toggle-slider { position: absolute; inset: 0; background: var(--border); border-radius: 12px; cursor: pointer; transition: all .3s; }
.toggle-slider::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: transform .3s; }
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── WORDS BOX ── */
.words-box { background: var(--surface-light); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; display: none; }
.words-box .wlabel { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.words-box .wtext { font-size: 12px; font-style: italic; color: var(--green); line-height: 1.45; }

/* ── BUTTONS ── */
.btn { display: block; width: 100%; padding: 12px; font-size: 14px; font-weight: 600; font-family: var(--font); border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--surface-light); color: var(--text); cursor: pointer; transition: all .2s; text-align: center; margin-bottom: 8px; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border: none; font-size: 15px; box-shadow: 0 4px 16px var(--accent-glow); }
.btn.primary:hover { transform: translateY(-1px); box-shadow: 0 6px 24px var(--accent-glow); }
.btn.save { background: var(--accent); color: #fff; border-color: var(--accent); display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn.save:hover { background: var(--accent2); }
.btn.small { padding: 6px 12px; font-size: 12px; width: auto; display: inline-flex; margin-bottom: 0; border-radius: 6px; }
.btn.upload { border-style: dashed; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 14px; }
.btn.upload:hover { background: var(--surface); border-color: var(--accent); }
.btn.clear-img { border-color: rgba(233,69,96,0.3); color: var(--accent); display: flex; align-items: center; justify-content: center; gap: 8px; padding: 14px; background: rgba(233,69,96,0.05); }
.btn.clear-img:hover { background: rgba(233,69,96,0.15); border-color: var(--accent); }
.canvas-hint { font-size: 11px; color: var(--muted); text-align: center; margin-top: -4px; margin-bottom: 14px; }

/* ── SLIDER ── */
.slider-section { margin-bottom: 16px; }
.slider-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.slider-header label { font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 0; }
.slider-header .slider-badge { font-size: 11px; background: var(--accent); color: #fff; padding: 2px 8px; border-radius: 4px; font-weight: 600; }
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row button { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-light); color: var(--muted); cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; transition: all .2s; flex-shrink: 0; }
.slider-row button:hover { border-color: var(--accent); color: var(--accent); }
input[type=range] { flex: 1; -webkit-appearance: none; height: 6px; border-radius: 3px; background: var(--border); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); cursor: pointer; box-shadow: 0 0 8px var(--accent-glow); }

/* ── TEMPLATE LIST ── */
.tpl-section { margin-top: 16px; }
.tpl-section-header { display: flex; align-items: center; justify-content: space-between; cursor: pointer; padding: 8px 0; border-top: 1px solid var(--border); }
.tpl-section-header span { font-size: 13px; font-weight: 600; color: var(--text); }
.tpl-section-header .arrow { font-size: 10px; color: var(--muted); transition: transform .2s; }
.tpl-section-header .arrow.open { transform: rotate(180deg); }
.tpl-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.tpl-item { background: var(--surface-light); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; font-size: 13px; cursor: pointer; text-align: left; font-family: var(--font); color: var(--text); transition: all .15s; display: flex; align-items: center; justify-content: space-between; }
.tpl-item:hover { background: var(--surface2); border-color: var(--accent); }
.tpl-item .tpl-name { display: flex; align-items: center; gap: 8px; }
.tpl-del { background: none; border: 1px solid rgba(233,69,96,0.3); border-radius: 6px; color: var(--accent); cursor: pointer; padding: 4px 8px; font-size: 11px; transition: all .2s; }
.tpl-del:hover { background: var(--accent); color: #fff; }
.tpl-empty { font-size: 12px; color: var(--muted); text-align: center; padding: 12px; }

/* ── CHEQUE PREVIEW ── */
.preview-section { position: sticky; top: 20px; }
.preview-label { font-size: 12px; color: var(--muted); margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.preview-label .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
#cheque-wrap { width: 100%; aspect-ratio: 660/270; position: relative; background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); }
#cheque-svg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
#cheque-bg-img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
.cf { position: absolute; font-family: var(--mono); color: #1a1a2e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 58%; user-select: none; cursor: default; }
.cf.draggable { cursor: grab; border: 1.5px dashed #4a90d9; padding: 2px 6px; border-radius: 4px; background: rgba(74,144,217,.12); }
.cf.draggable:active { cursor: grabbing; }
#cf-amtWords { max-width: 74%; white-space: normal; line-height: 1.4; }
.hint { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.6; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }

/* ── TRANSFORM BOX ── */
#transform-box { position: absolute; border: 1px solid #4a90d9; pointer-events: none; z-index: 10; }
#transform-box::after { content:''; position:absolute; left:50%; top:-20px; width:1px; height:20px; background:#4a90d9; transform:translateX(-50%); }
.th-rot { position:absolute; left:50%; top:-24px; width:8px; height:8px; border:1px solid #4a90d9; background:#fff; transform:translateX(-50%); pointer-events:all; cursor:crosshair; }
.th-res { position:absolute; width:6px; height:6px; border:1px solid #4a90d9; background:#fff; pointer-events:all; }
#th-tl { top:-3px; left:-3px; cursor:nwse-resize; }
#th-tr { top:-3px; right:-3px; cursor:nesw-resize; }
#th-bl { bottom:-3px; left:-3px; cursor:nesw-resize; }
#th-br { bottom:-3px; right:-3px; cursor:nwse-resize; }
#th-ml { top:50%; left:-3px; transform:translateY(-50%); cursor:ew-resize; }
#th-mr { top:50%; right:-3px; transform:translateY(-50%); cursor:ew-resize; }

.prop-btn { width: 32px; height: 32px; padding: 0; background: var(--surface-light); color: var(--text); border: 1px solid var(--border); border-radius: 6px; }
.prop-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── TAB PANELS ── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── RESPONSIVE ── */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .header { padding: 14px 16px; flex-wrap: wrap; gap: 10px; }
  .header-actions { width: 100%; justify-content: flex-end; }
  .main-content { padding: 0 12px 32px; }
  .preview-section { position: static; }
}
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: flex !important; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; align-items: center; justify-content: center; }
  @page { size: landscape; margin: 5mm; }
}
