* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #f0f2f5; color: #333; line-height: 1.6; }
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

.header { background: linear-gradient(135deg, #1a237e, #283593); color: white; padding: 4px 0; box-shadow: 0 1px 4px rgba(0,0,0,0.1); }
.header .container { display: flex; align-items: center; gap: 14px; }
.header .logo { height: 34px; width: auto; padding: 3px; background: white; border-radius: 4px; object-fit: contain; flex-shrink: 0; }
.header h1 { font-size: 18px; font-weight: 600; }
.header p { font-size: 12px; opacity: 0.85; }

.card { background: white; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); padding: 18px; margin-bottom: 18px; }
.card h2 { font-size: 16px; margin-bottom: 14px; color: #1a237e; border-bottom: 1px solid #e8eaf6; padding-bottom: 8px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 0; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 0; }
.form-group { margin-bottom: 8px; }
.form-group label { display: block; font-weight: 600; font-size: 11px; color: #555; margin-bottom: 3px; text-transform: uppercase; letter-spacing: 0.3px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 6px 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 13px; transition: border-color 0.2s; background: #fafafa; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: #1a237e; box-shadow: 0 0 0 2px rgba(26,35,126,0.08); }
.form-group textarea { resize: vertical; min-height: 50px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 10px; }
table { width: 100%; border-collapse: collapse; min-width: 700px; }
table th { background: #1a237e; color: white; padding: 6px 8px; text-align: left; font-size: 11px; font-weight: 500; white-space: nowrap; }
table td { padding: 4px 6px; border-bottom: 1px solid #eee; font-size: 12px; }
table td input, table td select { width: 100%; padding: 4px 5px; border: 1px solid #ddd; border-radius: 3px; font-size: 12px; background: #fafafa; }
table td input:focus, table td select:focus { outline: none; border-color: #1a237e; }
table td input[readonly] { background: #f5f5f5; font-weight: 600; }
table tbody tr:hover { background: #f8f9fa; }

.btn { padding: 6px 16px; border: none; border-radius: 4px; font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.2s; display: inline-flex; align-items: center; gap: 5px; text-decoration: none; }
.btn-primary { background: #1a237e; color: white; }
.btn-primary:hover { background: #283593; }
.btn-success { background: #2e7d32; color: white; }
.btn-success:hover { background: #388e3c; }
.btn-danger { background: #c62828; color: white; }
.btn-danger:hover { background: #d32f2f; }
.btn-sm { padding: 5px 12px; font-size: 11px; border-radius: 6px; }
.btn-print { background: #1565c0; color: white; border-radius: 6px; font-weight: 600; transition: all 0.2s; border: none; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.btn-print:hover { background: #1976d2; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(21,101,192,0.3); }
.btn-excel { background: #1b5e20; color: white; display: inline-flex; align-items: center; gap: 4px; border-radius: 6px; font-weight: 600; transition: all 0.2s; border: none; cursor: pointer; }
.btn-excel:hover { background: #2e7d32; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(27,94,32,0.3); }
.btn-pdf { background: #b71c1c; color: white; display: inline-flex; align-items: center; gap: 4px; border-radius: 6px; font-weight: 600; transition: all 0.2s; border: none; cursor: pointer; }
.btn-pdf:hover { background: #c62828; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(183,28,28,0.3); }

.add-row-btn { background: #e8eaf6; color: #1a237e; border: 1px dashed #1a237e; padding: 5px 12px; font-size: 11px; cursor: pointer; border-radius: 4px; margin-bottom: 8px; transition: all 0.2s; }
.add-row-btn:hover { background: #c5cae9; }

.total-section { text-align: right; padding: 10px 16px; background: #f8f9fc; border-radius: 4px; margin-top: 8px; border: 1px solid #e8eaf6; }
.total-section p { margin: 2px 0; }
.total-line { font-size: 13px; color: #555; }
.grand-total { font-size: 16px; font-weight: 700; color: #1a237e; }

.doc-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border: 1px solid #eee; border-radius: 4px; margin-bottom: 4px; transition: all 0.2s; }
.doc-item:hover { background: #f5f5f5; border-color: #1a237e; }
.doc-info { flex: 1; min-width: 0; }
.doc-info strong { font-size: 13px; color: #1a237e; }
.doc-meta { font-size: 11px; color: #666; margin-top: 1px; word-break: break-word; }
.doc-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; flex-wrap: wrap; }

.alert { padding: 8px 14px; border-radius: 4px; margin-bottom: 10px; font-weight: 500; font-size: 12px; }
.alert-success { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.alert-error { background: #fce4ec; color: #c62828; border: 1px solid #ef9a9a; }

.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; padding: 10px; background: #f5f5f5; border-radius: 4px; }
.filter-bar label { font-weight: 600; font-size: 11px; color: #555; }
.filter-bar input, .filter-bar select { padding: 5px 8px; border: 1px solid #ddd; border-radius: 3px; font-size: 12px; }
.filter-bar input:focus, .filter-bar select:focus { outline: none; border-color: #1a237e; }

.section-title { font-size: 13px; font-weight: 700; color: #1a237e; margin: 12px 0 6px; padding: 4px 0; border-bottom: 1px solid #e8eaf6; }

.party-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 12px; }
.party-box { border: 1px solid #e0e0e0; border-radius: 6px; padding: 14px; background: #fafafa; }
.party-box-title { font-size: 12px; font-weight: 700; color: #1a237e; margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid #e0e0e0; text-transform: uppercase; letter-spacing: 0.5px; }
.party-box .form-group { margin-bottom: 6px; }
.party-box .form-group:last-child { margin-bottom: 0; }
.party-box .form-group input,
.party-box .form-group select,
.party-box .form-group textarea { background: white; }

select[name="variant[]"] { text-transform: uppercase; }
select[name="variant[]"] option { text-transform: uppercase; }

.upload-section { margin: 10px 0; padding: 12px; background: #f5f7ff; border: 1px dashed #1a237e; border-radius: 6px; }
.upload-section input[type="file"] { font-size: 12px; }
@media (max-width: 768px) {
  .upload-section { padding: 10px; }
  .upload-section > div:first-child { flex-direction: column; align-items: stretch !important; gap: 8px !important; }
  .upload-section input[type="file"] { font-size: 14px; min-height: 40px; padding: 6px 0; }
  .upload-section .btn { width: 100%; justify-content: center; }
}

.row-error { background: #fff0f0 !important; border-left: 3px solid #c62828; }
.row-error td { background: transparent !important; }
.row-error td input, .row-error td select { border-color: #ef9a9a !important; background: #fff5f5 !important; }
.error-icon { display: inline-block; cursor: help; font-size: 16px; margin-left: 4px; color: #c62828; font-weight: bold; line-height: 1; }

.hidden { display: none; }

@media print { .no-print { display: none !important; } body { background: white; } .card { box-shadow: none; border: none; padding: 0; } }

@media (min-width: 769px) {
  .container { max-width: 1100px; }
  .card { padding: 20px; }
  .form-row { gap: 18px; margin-bottom: 0; }
  .form-row-3 { gap: 16px; margin-bottom: 0; }
  .form-group { margin-bottom: 12px; }
  .section-title { margin: 14px 0 8px; padding: 4px 0; }
}

@media (hover: none) and (pointer: coarse) {
  input, select, textarea, button, .btn, .add-row-btn, a { touch-action: manipulation; }
}

@media (max-width: 768px) {
  .container { padding: 10px; }
  .header { padding: 8px 0; }
  .header .container { flex-direction: column; text-align: center; gap: 6px; }
  .header .logo { height: 34px; width: auto; padding: 3px; background: white; border-radius: 4px; }
  .header h1 { font-size: 16px; }
  .header p { font-size: 11px; }
  .header .container > div:last-child { gap: 4px !important; flex-wrap: nowrap !important; justify-content: center; width: 100%; }
  .header .container > div:last-child .btn { padding: 5px 8px; font-size: 10px; min-height: 30px; white-space: nowrap; flex: 1 1 auto; }
  .header .container > div:last-child > span { width: 100%; text-align: center; margin-bottom: 4px; }
  .card { padding: 12px; }
  .card h2 { font-size: 15px; }
  .form-row, .form-row-3, .party-grid { grid-template-columns: 1fr; gap: 8px; }
  .form-group label { font-size: 12px; }
  .form-group input, .form-group select, .form-group textarea { padding: 10px 12px; font-size: 15px; min-height: 44px; }
  .form-group textarea { min-height: 60px; }
  .party-box { padding: 10px; }
  .party-box .form-group input,
  .party-box .form-group select,
  .party-box .form-group textarea { padding: 10px 12px; font-size: 15px; min-height: 44px; }
  .party-box .form-group textarea { min-height: 50px; }
  .party-box > div[style*="grid"] { grid-template-columns: 1fr !important; gap: 8px !important; }
  table td input, table td select { padding: 8px 6px; font-size: 15px; min-height: 40px; }
  table th { font-size: 10px; padding: 8px 4px; }
  table td { padding: 5px; font-size: 11px; }
  .btn { padding: 10px 16px; font-size: 14px; min-height: 44px; justify-content: center; }
  .btn-sm { padding: 8px 12px; font-size: 12px; min-height: 36px; }
  .add-row-btn { padding: 10px 16px; font-size: 13px; min-height: 44px; width: 100%; justify-content: center; display: flex; align-items: center; gap: 6px; }
  .filter-bar { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; }
  .filter-bar input, .filter-bar select { padding: 10px 12px; font-size: 15px; min-height: 44px; width: 100%; }
  .filter-bar .btn { width: 100%; justify-content: center; }
  .filter-bar > span { display: none; }
  .filter-bar > a.btn { text-align: center; }
  .doc-item { flex-direction: column; align-items: stretch; gap: 8px; }
  .doc-actions { justify-content: stretch; flex-wrap: wrap; }
  .doc-actions a, .doc-actions form, .doc-actions button { flex: 1; min-width: 0; }
  .doc-actions .btn { justify-content: center; width: 100%; }
  .total-section { text-align: left; padding: 10px; }
  .total-line { font-size: 12px; }
  .grand-total { font-size: 16px; }
  table { min-width: 0; }
  .section-title { font-size: 12px; margin: 10px 0 5px; }

  #itemsBody tr {
    display: block;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 12px 12px 6px;
    margin-bottom: 10px;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    position: relative;
  }
  #itemsBody tr td {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    border: none;
    font-size: 12px;
    width: 100% !important;
  }
  #itemsBody tr td:first-child {
    font-weight: 700;
    font-size: 14px;
    color: #1a237e;
    padding: 0 0 6px 0;
    margin-bottom: 4px;
    border-bottom: 1px solid #e8eaf6;
  }
  #itemsBody tr td:first-child::before {
    content: 'Item ';
  }
  #itemsBody tr td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    color: #555;
    font-size: 11px;
    min-width: 70px;
    flex-shrink: 0;
  }
  #itemsBody tr td:last-child {
    position: absolute;
    top: 6px;
    right: 6px;
    padding: 0;
    border: none;
    width: auto !important;
  }
  #itemsBody tr td input,
  #itemsBody tr td select {
    flex: 1;
    min-width: 0;
    width: auto;
  }
  #itemsBody tr td input[readonly] {
    background: #f5f5f5;
    font-weight: 600;
  }
  .table-wrap table thead {
    display: none;
  }
}

@media (max-width: 480px) {
  .container { padding: 6px; }
  .card { padding: 10px; margin-bottom: 10px; border-radius: 6px; }
  .card h2 { font-size: 14px; margin-bottom: 10px; }
  .header .container > div:last-child .btn { font-size: 9px; padding: 4px 6px; min-height: 26px; }
  .header .container > div:last-child > span { font-size: 11px !important; }
  .header h1 { font-size: 14px; }
  .header p { font-size: 10px; }
  .header .logo { height: 34px; width: auto; padding: 3px; background: white; border-radius: 4px; }
  .form-group label { font-size: 11px; }
  .form-group input, .form-group select, .form-group textarea { padding: 8px 10px; font-size: 14px; min-height: 40px; }
  .party-box { padding: 8px; }
  .party-box .form-group input,
  .party-box .form-group select,
  .party-box .form-group textarea { padding: 8px 10px; font-size: 14px; min-height: 40px; }
  .btn { padding: 8px 14px; font-size: 13px; min-height: 40px; }
  .btn-sm { padding: 6px 10px; font-size: 11px; min-height: 34px; }
  table td input, table td select { padding: 6px 4px; font-size: 13px; min-height: 34px; }
  .add-row-btn { padding: 8px 12px; font-size: 12px; min-height: 40px; }
  .doc-info strong { font-size: 12px; }
  .doc-meta { font-size: 10px; }
  .alert { font-size: 11px; padding: 6px 10px; }
  .total-section { padding: 8px; }
  #itemsBody tr { padding: 10px 10px 4px; }
  #itemsBody tr td { font-size: 11px; }
  #itemsBody tr td[data-label]::before { min-width: 60px; font-size: 10px; }
}