:root {
  --color-bg: #f3f4f6;
  --color-surface: #ffffff;
  --color-border: #e2e4e9;
  --color-border-strong: #d1d5db;
  --color-text: #1f2430;
  --color-text-muted: #6b7280;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-soft: #eff4ff;
  --color-danger: #dc2626;
  --color-success: #16a34a;

  --toolbar-width: 92px;
  --sidebar-width: 280px;
  --header-height: 56px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-paper: 0 8px 24px rgba(20, 24, 33, 0.14), 0 2px 6px rgba(20, 24, 33, 0.08);
  --shadow-panel: 0 1px 2px rgba(20, 24, 33, 0.05);

  --transition-fast: 150ms ease;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior-y: none; 
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

button, input {
  font-family: inherit;
}


.tool-btn:focus-visible,
.app-header__status:focus-visible,
input:focus-visible,
.switch__track:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

input[type="range"]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
}

.switch input:focus-visible + .switch__track {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; 
  overflow: hidden;
}


.app-header {
  height: var(--header-height);
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 20;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 15px;
  color: var(--color-text);
}

.app-header__brand svg {
  color: var(--color-primary);
}

.app-header__status {
  font-size: 13px;
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
}


.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.toolbar {
  width: var(--toolbar-width);
  min-width: var(--toolbar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 14px 10px;
  gap: 6px;
  overflow-y: auto;
}

.tool-divider {
  height: 1px;
  background: var(--color-border);
  margin: 6px 4px;
}

.tool-spacer {
  flex: 1;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 4px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.tool-btn svg {
  width: 20px;
  height: 20px;
}

.tool-btn:hover:not(:disabled) {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.tool-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.tool-btn:disabled {
  color: #c3c7d1;
  cursor: not-allowed;
}

.tool-btn--primary {
  background: var(--color-primary);
  color: #fff;
}

.tool-btn--primary:hover {
  background: var(--color-primary-hover);
  color: #fff;
}

.tool-btn--print {
  background: var(--color-text);
  color: #fff;
}

.tool-btn--print:hover:not(:disabled) {
  background: #000;
  color: #fff;
}

.tool-btn--print:disabled {
  background: #e5e7eb;
  color: #b3b7c1;
}

.tool-btn--success {
  background: var(--color-success);
  color: #fff;
}

.tool-btn--success:hover:not(:disabled) {
  background: #15803d;
  color: #fff;
}

.tool-btn--danger {
  background: var(--color-surface);
  color: var(--color-danger);
  border: 1px solid #fecaca;
}

.tool-btn--danger:hover:not(:disabled) {
  background: #fef2f2;
  color: var(--color-danger);
}

.tool-btn.hidden {
  display: none !important;
}

.workspace {
  flex: 1;
  min-width: 0;
  background:
    radial-gradient(circle at 1px 1px, rgba(0,0,0,0.045) 1px, transparent 0) 0 0/16px 16px,
    #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 40px;
  --paper-scale: 1;
}

.a4-paper-wrapper {
  width: calc(794px * var(--paper-scale));
  height: calc(1123px * var(--paper-scale));
  flex-shrink: 0;
}

.a4-paper {
  position: relative;
  width: 794px;
  height: 1123px;
  background: #ffffff;
  box-shadow: var(--shadow-paper);
  transform: scale(var(--paper-scale));
  transform-origin: top left;
}

.a4-paper canvas {
  position: absolute;
  top: 0;
  left: 0;
}

.a4-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #c3c7d1;
  pointer-events: none;
  user-select: none;
}

.a4-placeholder p {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
}

.a4-placeholder.hidden {
  display: none;
}

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  padding: 18px 16px 40px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 14px 16px 16px;
  box-shadow: var(--shadow-panel);
}

.panel__title {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.field {
  margin-bottom: 12px;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 6px;
}

.field label .unit {
  font-weight: 400;
  color: var(--color-text-muted);
  font-size: 11px;
}

.field label .value {
  font-weight: 600;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}

.field input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition-fast);
}

.field input[type="number"]:focus {
  outline: none;
  border-color: var(--color-primary);
}

.field input[type="number"]:disabled {
  background: #f9fafb;
  color: #b3b7c1;
  cursor: not-allowed;
}

.field input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--color-border-strong);
  outline: none;
  cursor: pointer;
}

.field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--color-primary);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.field input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.field input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--color-primary);
  cursor: pointer;
}

.field input[type="range"]:disabled {
  background: #edeef1;
  cursor: not-allowed;
}

.field input[type="range"]:disabled::-webkit-slider-thumb {
  background: #c3c7d1;
  box-shadow: 0 0 0 1px #c3c7d1;
}

.field--toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field--toggle label:first-child {
  margin-bottom: 0;
  font-size: 12.5px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch__track {
  position: absolute;
  inset: 0;
  background: var(--color-border-strong);
  border-radius: 999px;
  transition: background var(--transition-fast);
  cursor: pointer;
}

.switch__track::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition-fast);
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.switch input:checked + .switch__track {
  background: var(--color-primary);
}

.switch input:checked + .switch__track::before {
  transform: translateX(18px);
}

.switch input:disabled + .switch__track {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 1200px) {
  :root {
    --sidebar-width: 250px;
  }
  .workspace {
    --paper-scale: 0.78;
  }
}

@media (max-width: 980px) {
  .app-body {
    flex-direction: column;
    overflow-y: auto;
  }

  .sidebar {
    width: 100%;
    min-width: 0;
    border-left: none;
    border-top: 1px solid var(--color-border);
    flex-direction: row;
    flex-wrap: wrap;
    padding: 20px;
  }

  .panel {
    flex: 1 1 260px;
  }
}

@media (max-width: 768px) {
  .app-body {

    display: block; 
    overflow-y: auto;
    overflow-x: hidden;

    padding-bottom: 90px; 
  }


  .toolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    background: var(--color-surface);
    border-right: none;
    border-top: 1px solid var(--color-border);
    border-bottom: none;
    z-index: 100;
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 12px rgba(0,0,0,0.05);

    scrollbar-width: none;
  }
  
  .toolbar::-webkit-scrollbar {
    display: none;
  }

  .tool-btn {
    flex: 0 0 auto;
    padding: 8px 14px;
    min-height: 48px;
  }

  .tool-divider {
    width: 1px;
    height: 30px;
    margin: auto 8px;
    flex-shrink: 0;
  }

  .tool-spacer {
    display: none;
  }

  .workspace {
    padding: 24px 16px;
    flex: none;
    display: flex;
    justify-content: center;

    --paper-scale: calc((100vw - 32px) / 794);

    min-height: calc(1123px * var(--paper-scale) + 48px);
  }

  .sidebar {
    padding: 16px;
    gap: 16px;
    flex: none;
  }

  .panel {
    flex: none;
    width: 100%;
  }

  .field input[type="number"] {
    font-size: 16px;
    padding: 10px 12px;
  }
  
  .field input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }
  
  .field input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
  }

  .field label {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .app-header__brand span {
    display: none;
  }
  .app-header {
    padding: 0 16px;
  }
}

.print-area {
  display: none;
}

@media print {
  html, body {
    margin: 0;
    padding: 0;
  }

  body * {
    visibility: hidden;
  }

  .print-area,
  .print-area * {
    visibility: visible;
  }

  .print-area {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 210mm;
    height: 297mm;
    margin: 0;
    padding: 0;
  }

  .print-area img {
    display: block;
    width: 210mm;
    height: 297mm;
  }

  @page {
    size: A4;
    margin: 0;
  }
}

.brand-logo {
  width: 30px; 
  height: 30px;
  padding: 2px; 
  border: 2px solid var(--color-border-strong); 
  border-radius: var(--radius-sm); 
  object-fit: contain; 
}