:root {
      --ink: #172033;
      --muted: #5f6b7a;
      --line: #d9e1ea;
      --soft: #f5f7fa;
      --panel: #ffffff;
      --teal: #003f91;
      --teal-dark: #002f70;
      --blue: #003f91;
      --red: #f20d0d;
      --rose: #c41230;
      --amber: #9a6412;
      --shadow: 0 12px 30px rgba(28, 38, 52, 0.10);
    }

    * { box-sizing: border-box; }

    body {
      margin: 0;
      font-family: Arial, Helvetica, sans-serif;
      color: var(--ink);
      background: #edf2f6;
    }

    header {
      background: #ffffff;
      background-size: cover;
      color: var(--ink);
      padding: 22px clamp(16px, 4vw, 42px);
      min-height: 138px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 20px;
      border-bottom: 5px solid var(--blue);
    }

    .logo-wrap {
      display: flex;
      align-items: center;
      gap: 18px;
      min-width: 0;
    }

    .logo {
      width: clamp(150px, 24vw, 260px);
      height: auto;
      display: block;
      flex: 0 0 auto;
    }

    .brand h1 {
      margin: 0 0 6px;
      font-size: clamp(24px, 4vw, 38px);
      line-height: 1;
      letter-spacing: 0;
      color: var(--red);
    }

    .brand p {
      margin: 0;
      color: var(--blue);
      font-size: 14px;
      line-height: 1.4;
      max-width: 660px;
    }

    .status {
      display: flex;
      align-items: center;
      gap: 8px;
      background: #f4f8ff;
      border: 1px solid #c8d9f4;
      border-radius: 8px;
      padding: 9px 11px;
      font-size: 13px;
      white-space: nowrap;
      color: var(--blue);
    }

    main {
      display: grid;
      grid-template-columns: minmax(0, 1.1fr) minmax(330px, .75fr);
      gap: 18px;
      padding: 18px clamp(12px, 3vw, 28px) 28px;
      max-width: 1420px;
      margin: 0 auto;
    }

    .workspace,
    .preview {
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: 8px;
      box-shadow: var(--shadow);
      min-width: 0;
    }

    .workspace { padding: 16px; }
    .preview { padding: 14px; align-self: start; position: sticky; top: 14px; }

    .service-tabs {
      display: grid;
      grid-template-columns: repeat(4, minmax(0, 1fr));
      gap: 8px;
      margin-bottom: 15px;
    }

    .tab {
      border: 1px solid var(--line);
      background: var(--soft);
      color: var(--ink);
      border-radius: 7px;
      min-height: 42px;
      padding: 8px 8px;
      font-weight: 700;
      cursor: pointer;
      font-size: 13px;
    }

    .tab.active {
      color: #fff;
      background: var(--teal);
      border-color: var(--teal);
    }

    .mini-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin: 0 0 13px;
    }

    .small-btn {
      border: 1px solid var(--line);
      background: #fff;
      color: var(--blue);
      border-radius: 7px;
      min-height: 34px;
      padding: 7px 10px;
      font-weight: 700;
      cursor: pointer;
      font-size: 12px;
    }

    .small-btn.primary {
      color: #fff;
      background: var(--blue);
      border-color: var(--blue);
    }

    .section {
      border-top: 1px solid var(--line);
      padding-top: 15px;
      margin-top: 15px;
    }

    .section:first-of-type {
      border-top: 0;
      padding-top: 0;
      margin-top: 0;
    }

    .section h2,
    .preview h2 {
      margin: 0 0 12px;
      font-size: 16px;
      color: var(--blue);
      letter-spacing: 0;
    }

    .grid {
      display: grid;
      grid-template-columns: repeat(4, minmax(0, 1fr));
      gap: 11px;
    }

    .grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

    label {
      display: block;
      font-size: 12px;
      font-weight: 700;
      color: var(--muted);
      margin-bottom: 5px;
    }

    input,
    select,
    textarea {
      width: 100%;
      border: 1px solid #c8d3df;
      border-radius: 6px;
      background: #fff;
      color: var(--ink);
      min-height: 38px;
      padding: 8px 9px;
      font-size: 14px;
      font-family: inherit;
    }

    textarea {
      min-height: 86px;
      resize: vertical;
      line-height: 1.35;
    }

    input:focus,
    select:focus,
    textarea:focus {
      outline: 3px solid rgba(9, 123, 123, .18);
      border-color: var(--teal);
    }

    .choice-grid {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 8px;
    }

    .choice {
      display: flex;
      align-items: center;
      gap: 8px;
      min-height: 38px;
      border: 1px solid var(--line);
      border-radius: 6px;
      padding: 8px 9px;
      font-size: 13px;
      background: #fff;
      cursor: pointer;
    }

    .choice input {
      width: 17px;
      min-height: 17px;
      flex: 0 0 auto;
      accent-color: var(--teal);
    }

    .actions {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 9px;
      margin: 13px 0 10px;
    }

    button.action {
      min-height: 42px;
      border: 0;
      border-radius: 7px;
      color: #fff;
      font-weight: 700;
      cursor: pointer;
      font-size: 14px;
    }

    .copy { background: var(--blue); }
    .print { background: #5b6472; }
    .download { background: #0f6f8f; }
    .combo { background: #106f46; grid-column: 1 / -1; }
    .clear { background: var(--rose); grid-column: 1 / -1; }

    .message {
      width: 100%;
      min-height: 520px;
      border: 1px solid #c8d3df;
      border-radius: 7px;
      padding: 11px;
      background: #fbfcfd;
      color: var(--ink);
      font-size: 13px;
      line-height: 1.35;
      white-space: pre-wrap;
    }

    .notice {
      margin-top: 10px;
      border-left: 4px solid var(--amber);
      background: #fff8ed;
      padding: 9px 10px;
      color: #68440f;
      font-size: 12px;
      line-height: 1.35;
      border-radius: 4px;
    }

    .toast {
      position: fixed;
      right: 18px;
      bottom: 18px;
      background: var(--ink);
      color: #fff;
      padding: 10px 12px;
      border-radius: 7px;
      box-shadow: var(--shadow);
      opacity: 0;
      transform: translateY(10px);
      transition: .2s ease;
      pointer-events: none;
      font-size: 13px;
    }

    .toast.show {
      opacity: 1;
      transform: translateY(0);
    }

    .print-area {
      display: none;
    }

    @media print {
      body > :not(.print-area) {
        display: none !important;
      }

      body {
        background: #fff;
        margin: 0;
      }

      .print-area {
        display: block !important;
        padding: 14mm;
        color: #172033;
        font-family: Arial, Helvetica, sans-serif;
        line-height: 1.35;
      }

      .print-head {
        display: flex;
        align-items: center;
        gap: 18px;
        border-bottom: 4px solid #003f91;
        padding-bottom: 14px;
        margin-bottom: 12px;
      }

      .print-head img {
        width: 190px;
        max-height: 95px;
        object-fit: contain;
      }

      .print-head h1 {
        margin: 0;
        color: #f20d0d;
        font-size: 28px;
      }

      .print-head p,
      .print-clinic strong,
      .print-footer {
        color: #003f91;
      }

      .print-clinic {
        font-size: 12px;
        color: #172033;
        line-height: 1.45;
        margin-bottom: 16px;
      }

      .print-area table {
        border-collapse: collapse;
        width: 100%;
        font-size: 13px;
      }

      .print-area th,
      .print-area td {
        border: 1px solid #d9e1ea;
        padding: 8px 9px;
        vertical-align: top;
      }

      .print-area th {
        width: 230px;
        text-align: left;
        background: #f4f8ff;
        color: #003f91;
      }

      .print-area td {
        white-space: pre-line;
      }

      .print-note {
        margin-top: 16px;
        background: #fff8ed;
        border-left: 5px solid #9a6412;
        padding: 10px;
      }

      .print-footer {
        margin-top: 18px;
        border-top: 2px solid #003f91;
        padding-top: 10px;
        font-size: 12px;
        text-align: center;
      }
    }

    @media (max-width: 980px) {
      header { align-items: flex-start; flex-direction: column; }
      main { grid-template-columns: 1fr; }
      .preview { position: static; }
      .grid, .grid.two, .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
      .service-tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    }

    @media (max-width: 620px) {
      main { padding: 10px; }
      .workspace, .preview { padding: 12px; }
      .service-tabs, .grid, .grid.two, .grid.three, .choice-grid, .actions {
        grid-template-columns: 1fr;
      }
      .message { min-height: 360px; }
      header { padding: 18px 14px; }
      .status { white-space: normal; }
    }
