  :root{
    --bg: #f7f8fb;
    --card: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;

    --accent: #2563eb;      /* blue */
    --danger: #ef4444;      /* red */
    --shadow: 0 8px 24px rgba(0,0,0,.06);
  }

  body {
    font-family: system-ui, Arial;
    margin: 20px;
    max-width: 900px;
    background: var(--bg);
    color: var(--text);
  }

  /* Fix: prevent width overflow from padding/border on mobile */
  *, *::before, *::after { box-sizing: border-box; }

  .row { 
    display: grid; 
    grid-template-columns: 1fr; 
    gap: 10px;
    max-width: 100%;
  }

  .row > * { max-width: 100%; }

  label { font-weight: 600; }

  input, textarea, button, select {
    font: inherit;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
  }

  /* Message input */
  #msg{
    width: 100%;
    min-height: 56px;          /* ~2–3 lines */
    resize: none;
    border-radius: 14px;
    background: #fff;
  }

  @media (min-width: 900px){
    #msg{ min-height: 60px; }
  }

  button {
    cursor: pointer;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    transition: transform .05s ease, opacity .15s ease;
  }

  button:hover { opacity: .92; }
  button:active { transform: translateY(1px); }

  button:disabled{
    opacity: .55;
    cursor: not-allowed;
  }

  .box {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card);
    box-shadow: var(--shadow);
  }

  .muted { color: var(--muted); }

  .error {
    color: var(--danger);
    white-space: pre-wrap;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid #fecaca;
    background: #fff1f2;
  }

  /* Hide error box when empty */
  #err:empty {
    display: none;
    margin-top: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
  }

  .reply {
    white-space: pre-wrap;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fbfbfd;
  }

  /* =========================================================
     ✅ TOP LAYOUT (matches your NEW HTML: .left + .quota-wrap)
     - Quota alone top-right
     - Lang + Send under Code (left)
     - "Quota remaining" LEFT of number
     ========================================================= */

  .top{
    display: grid;
    grid-template-columns: 1fr auto;   /* left takes space, quota stays tight right */
    gap: 14px;
    align-items: start;
  }

  .left{
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
  }

  .controls{
    display:flex;
    gap:10px;
    align-items:center;
    justify-content:flex-start;
    flex-wrap:wrap;
  }
  .controls > * { flex: 0; }

  /* Code field wrapper */
  .code-field{
    width: fit-content;
    max-width: 100%;
  }

  /* Code input: fixed “8-char” friendly width */
  #code{
    width: 16ch;        /* ~8 chars + air */
    max-width: 190px;   /* safety */
  }

  /* Quota: label LEFT, badge RIGHT */
  .quota-wrap{
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    white-space: nowrap;
  }

  .quota-label{
    font-weight: 600;
    font-size: 12px;
    white-space: nowrap;
  }

  /* Mobile: keep same idea */
  @media (max-width: 480px){
    .top{ gap: 10px; }
    #code{ width: 16ch; max-width: 170px; }
  }

  /* quota badge */
  #quota{
    display: inline-block;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid #c7d2fe;
    background: #eef2ff;
    color: #1e3a8a;
    font-weight: 700;
  }

  /* file rows + thumbnails */
  .file-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
  }

  .thumb {
    width: 80px;
    height: 80px;
    border: 1px solid #ddd;
    border-radius: 10px;
    object-fit: cover;
    display: none;
  }

  @media (max-width: 768px) {
    .thumb { width: 80px; height: 80px; }
  }

  @media (max-width: 420px) {
    .thumb { width: 60px; height: 60px; }
  }

  /* loading spinner */
  .loader {
    display: none;
    margin: 12px auto;
    width: 48px;
    height: 48px;
    border: 5px solid #e0e0e0;
    border-top-color: #333;
    border-radius: 50%;
    animation: spin 1s linear infinite;
  }

  @keyframes spin { to { transform: rotate(360deg); } }

  .loading-text {
    text-align: center;
    margin-top: 8px;
    font-size: 0.95em;
  }

  /* polish */
  input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
  }

  input:hover, textarea:hover, select:hover { border-color: #d1d5db; }

  #reply { background: linear-gradient(180deg, #fbfbfd 0%, #f8fafc 100%); }

  button#sendBtn {
    box-shadow: 0 10px 18px rgba(37, 99, 235, 0.18);
  }
  button#sendBtn:hover {
    box-shadow: 0 12px 22px rgba(37, 99, 235, 0.22);
  }

  /* quota color states */
  #quota.quota-ok {
    border-color: #bbf7d0;
    background: #ecfdf5;
    color: #065f46;
  }

  #quota.quota-warn {
    border-color: #fde68a;
    background: #fffbeb;
    color: #92400e;
  }

  #quota.quota-low {
    border-color: #fecaca;
    background: #fff1f2;
    color: #991b1b;
  }

  /* Image zoom modal */
  #imgModal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.78);
    z-index: 9999;
    padding: 16px;
  }

  #imgModal.open { display: block; }

  #imgModal .modal-inner{
    height: 100%;
    display: grid;
    place-items: center;
  }

  #imgModalImg{
    max-width: 92vw;
    max-height: 88vh;
    object-fit: contain;
    border-radius: 12px;
    background: rgba(255,255,255,.06);
  }

  #imgModalHint{
    margin-top: 10px;
    color: rgba(255,255,255,.85);
    text-align: center;
    font-size: 14px;
  }
