* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Tahoma", "Sarabun", Arial, sans-serif;
    background: #f6f8fb;
    color: #0f172a;
}

a {
    color: #1d4ed8;
    text-decoration: none;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, .18), transparent 30%),
        linear-gradient(135deg, #eff6ff, #f8fafc);
}

.login-card {
    width: min(460px, 100%);
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 28px;
    padding: 32px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, .10);
}

.login-card.wide {
    width: min(760px, 100%);
}

.brand-badge {
    display: inline-block;
    background: #dbeafe;
    color: #1d4ed8;
    padding: 6px 12px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 13px;
    margin-bottom: 12px;
}

h1, h2, h3, h4 {
    margin-top: 0;
}

h1 {
    font-size: 28px;
    margin-bottom: 8px;
}

h2 {
    margin-bottom: 6px;
}

h3 {
    margin-top: 22px;
    margin-bottom: 12px;
}

.muted {
    color: #64748b;
}

form {
    margin-top: 0;
}

label {
    display: block;
    font-weight: 700;
    color: #334155;
    margin-bottom: 14px;
}

small {
    display: block;
    margin-top: 6px;
}

input, select, textarea {
    width: 100%;
    margin-top: 8px;
    border: 1px solid #cbd5e1;
    border-radius: 16px;
    padding: 13px 14px;
    outline: none;
    font-size: 15px;
    background: #fff;
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 4px #dbeafe;
}

input:disabled {
    background: #f1f5f9;
    color: #94a3b8;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #0f172a;
    border-radius: 14px;
    padding: 11px 16px;
    font-weight: 800;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.btn.primary {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: #fff;
}

.btn.full {
    width: 100%;
}

.btn.small {
    padding: 8px 12px;
    font-size: 13px;
}

.alert {
    border-radius: 16px;
    padding: 12px 14px;
    margin: 16px 0;
    font-weight: 700;
}

.alert.error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.alert.success {
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

.setup-note {
    margin-top: 18px;
    color: #64748b;
    text-align: center;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.topbar {
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 0 28px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.container {
    width: min(1180px, calc(100% - 32px));
    margin: 28px auto;
}

.hero {
    background: linear-gradient(135deg, #1d4ed8, #0ea5e9);
    color: #fff;
    border-radius: 30px;
    padding: 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    box-shadow: 0 20px 60px rgba(37, 99, 235, .20);
    margin-bottom: 22px;
}

.hero.mini {
    padding: 24px;
}

.hero p {
    color: #dbeafe;
    margin-bottom: 0;
}

.hero .brand-badge {
    background: rgba(255,255,255,.18);
    color: #fff;
}

.hero-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
    margin: 22px 0;
}

.stat-card, .card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 26px;
    padding: 22px;
    box-shadow: 0 8px 28px rgba(15, 23, 42, .05);
}

.stat-card span {
    color: #64748b;
    font-weight: 700;
}

.stat-card strong {
    display: block;
    font-size: 34px;
    margin-top: 8px;
}

.card {
    margin-bottom: 18px;
}

.card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}

.card-head p {
    margin: 6px 0 0;
    color: #64748b;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    color: #64748b;
    background: #f8fafc;
    padding: 12px;
    white-space: nowrap;
}

td {
    padding: 13px 12px;
    border-top: 1px solid #e2e8f0;
    vertical-align: top;
}

.empty {
    text-align: center;
    color: #94a3b8;
    padding: 28px;
}

.pill {
    background: #eef2ff;
    color: #3730a3;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 800;
}

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.form-panel {
    background: #f8fafc;
    border-radius: 24px;
    padding: 18px;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
}

.search-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 10px;
    margin: 0 0 18px;
}

.company-preview,
.doc-company {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 22px;
    padding: 16px;
    margin-bottom: 18px;
}

.logo-box {
    width: 90px;
    height: 90px;
    border-radius: 18px;
    background: #fde047;
    color: #0f172a;
    font-weight: 900;
    display: grid;
    place-items: center;
    overflow: hidden;
    flex-shrink: 0;
}

.logo-box.small {
    width: 60px;
    height: 60px;
    font-size: 12px;
}

.logo-box img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
}

.quote-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 20px;
    align-items: start;
}

.quote-main {
    min-width: 0;
}

.quote-side {
    min-width: 0;
}

.sticky-card {
    position: sticky;
    top: 88px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    padding: 14px;
}

.checkbox-row input,
.checkbox-mini input {
    width: auto;
    margin: 0;
}

.coverage-flags {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.flag {
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #94a3b8;
    padding: 10px 12px;
    border-radius: 16px;
    font-weight: 800;
    font-size: 13px;
}

.flag.ok {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #047857;
}

.flag.off {
    background: #f8fafc;
    border-color: #e2e8f0;
    color: #94a3b8;
}

.disabled-box {
    opacity: .45;
}

.items-wrap {
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
}

.item-row {
    display: grid;
    grid-template-columns: auto 1fr 160px auto;
    gap: 10px;
    align-items: center;
}

.item-row input {
    margin-top: 0;
}

.doc-preview {
    font-size: 13px;
}

.doc-preview h3 {
    margin: 0 0 8px;
}

.doc-title {
    border-top: 1px solid #e2e8f0;
    padding-top: 14px;
}

.preview-price-box,
.price-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    padding: 14px;
    margin-bottom: 12px;
}

.price-line,
.price-total {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 0;
}

.muted-line {
    color: #64748b;
    font-size: 12px;
}

.price-total {
    border-top: 1px solid #e2e8f0;
    margin-top: 8px;
    padding-top: 10px;
    color: #1d4ed8;
    font-size: 16px;
    font-weight: 900;
}

.provider-footer {
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1e3a8a;
    border-radius: 18px;
    padding: 14px;
    margin-top: 16px;
}

.provider-footer p {
    margin: 6px 0;
}

.quote-container {
    width: min(980px, calc(100% - 32px));
}

.quote-paper {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 26px;
    padding: 34px;
    box-shadow: 0 8px 28px rgba(15, 23, 42, .05);
}

.quote-header {
    display: flex;
    gap: 18px;
    align-items: flex-start;
    border-bottom: 2px solid #0f172a;
    padding-bottom: 18px;
}

.print-logo {
    width: 96px;
    height: 96px;
}

.quote-header h1 {
    font-size: 24px;
}

.quote-header p,
.quote-title-row p {
    margin: 4px 0;
    color: #475569;
}

.quote-title-row {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin: 24px 0;
}

.text-right {
    text-align: right;
}

.quote-section {
    margin: 22px 0;
}

.quote-section h3 {
    margin: 0 0 10px;
    background: #f1f5f9;
    border-left: 4px solid #2563eb;
    padding: 10px 12px;
    border-radius: 8px;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.info-grid div {
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 10px;
}

.info-grid span {
    display: block;
    color: #64748b;
    font-size: 12px;
    margin-bottom: 4px;
}

.coverage-table {
    border: 1px solid #e2e8f0;
}

.coverage-table td:first-child {
    width: 65%;
}

.coverage-table td:last-child {
    text-align: right;
    font-weight: 800;
}

.price-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.quote-footer {
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 20px;
    margin-top: 34px;
    border-top: 1px solid #e2e8f0;
    padding-top: 22px;
}

.signature-box {
    text-align: center;
    align-self: end;
}

.signature-line {
    height: 54px;
    border-bottom: 1px solid #0f172a;
    margin-bottom: 8px;
}

@media (max-width: 980px) {
    .quote-layout {
        grid-template-columns: 1fr;
    }

    .sticky-card {
        position: static;
    }

    .coverage-flags,
    .price-options,
    .info-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 800px) {
    .grid-2, .grid-3, .stats-grid, .search-row {
        grid-template-columns: 1fr;
    }

    .hero, .card-head, .quote-title-row, .quote-footer {
        align-items: flex-start;
        flex-direction: column;
        display: flex;
    }

    .topbar {
        padding: 10px 14px;
        align-items: flex-start;
        flex-direction: column;
    }

    .hide-mobile {
        display: none;
    }

    .item-row {
        grid-template-columns: auto 1fr;
    }
}

@media print {
    body {
        background: #fff;
    }

    .no-print,
    .topbar {
        display: none !important;
    }

    .container,
    .quote-container {
        width: 100%;
        margin: 0;
    }

    .quote-paper {
        border: 0;
        border-radius: 0;
        box-shadow: none;
        padding: 0;
    }

    .quote-section {
        break-inside: avoid;
    }

    a {
        color: inherit;
    }
}


/* =========================
   Set 3 layout refinements
   ========================= */

.quotation-create-page .container {
    width: min(1260px, calc(100% - 36px));
}

.quotation-create-page .card {
    padding: 24px;
}

.quotation-create-page .card h2 {
    font-size: 24px;
    line-height: 1.25;
}

.quotation-create-page .card h3 {
    font-size: 18px;
    margin-top: 24px;
}

.price-input-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 16px 0;
}

.addon-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 240px;
    gap: 16px;
    align-items: end;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 22px;
    padding: 16px;
    margin-bottom: 16px;
}

.switch-row {
    display: grid !important;
    grid-template-columns: 24px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    border: 0 !important;
    font-weight: 700;
}

.switch-row input,
.choice-card input,
.checkbox-mini input {
    width: 18px !important;
    height: 18px !important;
    margin: 0 !important;
    padding: 0 !important;
    flex: 0 0 auto;
}

.switch-row small,
.choice-card small {
    display: block;
    color: #64748b;
    font-weight: 400;
    margin-top: 4px;
    line-height: 1.35;
}

.compact-field {
    margin: 0;
}

.choice-panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 22px;
    padding: 16px;
    margin: 16px 0 22px;
}

.choice-title {
    font-weight: 900;
    color: #0f172a;
    margin-bottom: 12px;
}

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

.choice-card {
    display: grid !important;
    grid-template-columns: 24px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    padding: 14px;
    margin: 0 !important;
    cursor: pointer;
    background: #f8fafc;
    transition: .15s ease;
}

.choice-card:has(input:checked) {
    border-color: #2563eb;
    background: #eff6ff;
    box-shadow: 0 0 0 4px #dbeafe;
}

.items-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 8px 0 12px;
}

.items-header h3 {
    margin: 0 0 4px;
}

.items-header p {
    margin: 0;
    color: #64748b;
}

.items-table {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
}

.items-table-head,
.item-row {
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr) 180px 70px;
    gap: 10px;
    align-items: center;
}

.items-table-head {
    color: #64748b;
    font-size: 13px;
    font-weight: 800;
    padding: 0 4px;
}

.item-row {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    padding: 10px;
}

.item-row input {
    margin-top: 0 !important;
}

.checkbox-mini {
    display: flex !important;
    align-items: center;
    justify-content: center;
    margin: 0 !important;
    height: 100%;
}

.logo-box {
    background: #fff;
    border: 1px solid #e2e8f0;
    padding: 6px;
    color: #0f172a;
    text-align: center;
    line-height: 1.15;
}

.logo-box img {
    width: auto !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
    display: block;
    margin: auto;
    border-radius: 0;
}

.logo-box.small {
    width: 72px;
    height: 72px;
}

.print-logo {
    width: 110px;
    height: 110px;
    border-radius: 22px;
}

/* keep round logos round when file itself is circular; do not crop or stretch */
.company-preview .logo-box,
.doc-company .logo-box,
.quote-header .logo-box {
    overflow: visible;
}

.doc-company {
    align-items: center;
}

.doc-company h3 {
    margin-top: 0;
}

.preview-price-box {
    border-color: #dbeafe;
    background: #f8fbff;
}

@media (max-width: 1100px) {
    .quote-layout {
        grid-template-columns: 1fr;
    }

    .quote-side {
        order: -1;
    }

    .sticky-card {
        position: static;
    }
}

@media (max-width: 800px) {
    .addon-card,
    .price-input-grid,
    .price-mode-grid,
    .items-table-head,
    .item-row {
        grid-template-columns: 1fr;
    }

    .items-table-head {
        display: none;
    }

    .checkbox-mini {
        justify-content: flex-start;
    }

    .items-header {
        align-items: flex-start;
        flex-direction: column;
    }
}


/* Set 7: quotation edit + reuse vehicle */
.reuse-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, .8fr);
    gap: 14px;
    align-items: end;
    border: 1px solid #dbeafe;
    background: #eff6ff;
    border-radius: 22px;
    padding: 16px;
    margin-bottom: 18px;
}

.reuse-help {
    color: #1e40af;
    font-size: 13px;
    line-height: 1.45;
    padding-bottom: 14px;
}

.danger-pill {
    background: #fee2e2 !important;
    color: #991b1b !important;
}

@media (max-width: 800px) {
    .reuse-panel {
        grid-template-columns: 1fr;
    }

    .reuse-help {
        padding-bottom: 0;
    }
}


/* Set 5 actions retained */
.inline-form {
    display: inline-flex;
    margin: 0;
}

.btn.danger {
    background: #dc2626;
    border-color: #dc2626;
    color: #fff;
}

.btn.danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}

.actions {
    align-items: center;
}


/* =========================
   Set 8: consistent controls + responsive polish
   ========================= */

/* ป้องกัน checkbox/radio ถูกบังคับ width:100% จาก input global */
input[type="checkbox"],
input[type="radio"] {
    width: 18px !important;
    height: 18px !important;
    min-width: 18px !important;
    min-height: 18px !important;
    margin: 0 !important;
    padding: 0 !important;
    display: inline-block;
    vertical-align: middle;
    accent-color: #2563eb;
    box-shadow: none !important;
}

/* input ปกติให้กว้างเต็ม แต่ไม่กระทบ checkbox/radio */
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
    max-width: 100%;
}

/* จัด checkbox/radio ให้อยู่บรรทัดเดียวกับข้อความเสมอ */
.checkbox-row,
.switch-row,
.choice-card,
.checkbox-mini {
    line-height: 1.35;
}

.checkbox-row {
    display: grid !important;
    grid-template-columns: 22px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
}

.switch-row {
    display: grid !important;
    grid-template-columns: 22px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
}

.choice-card {
    display: grid !important;
    grid-template-columns: 22px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
}

.checkbox-mini {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

/* ปรับแถวรายการให้วางตรงกัน ไม่โดดไปมา */
.items-table-head,
.item-row {
    grid-template-columns: 64px minmax(180px, 1fr) minmax(120px, 180px) 76px !important;
}

.item-row .btn.small {
    width: 100%;
}

/* ฟอร์มเลือกข้อมูลรถเดิม */
.reuse-panel label {
    margin-bottom: 0;
}

.reuse-panel select {
    margin-top: 8px;
}

/* ปุ่มในตารางไม่เบียด */
.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.actions .btn,
.actions .inline-form {
    flex: 0 0 auto;
}

/* Responsive: Tablet */
@media (max-width: 1100px) {
    .container {
        width: min(100% - 24px, 100%);
    }

    .quote-layout,
    .gov-layout {
        grid-template-columns: 1fr !important;
    }

    .quote-side,
    .gov-side {
        order: -1;
    }

    .sticky-card {
        position: static !important;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
        padding: 12px 16px;
        gap: 10px;
    }

    .nav-user {
        width: 100%;
        gap: 8px;
    }
}

/* Responsive: Mobile */
@media (max-width: 760px) {
    body {
        font-size: 14px;
    }

    .container {
        width: calc(100% - 16px);
        margin: 12px auto;
    }

    .hero {
        border-radius: 22px;
        padding: 18px;
    }

    .card,
    .quotation-create-page .card {
        border-radius: 20px;
        padding: 16px;
    }

    .grid-2,
    .grid-3,
    .price-input-grid,
    .price-mode-grid,
    .reuse-panel,
    .addon-card {
        grid-template-columns: 1fr !important;
    }

    .items-table-head {
        display: none !important;
    }

    .item-row {
        grid-template-columns: 28px 1fr !important;
        align-items: center;
    }

    .item-row input[name^="item_name"],
    .item-row input[name^="item_amount"],
    .item-row .btn.small {
        grid-column: 1 / -1;
    }

    .checkbox-mini {
        justify-content: flex-start !important;
    }

    .choice-card,
    .switch-row,
    .checkbox-row {
        align-items: start;
    }

    .btn {
        min-height: 42px;
    }

    .actions .btn,
    .actions .inline-form,
    .actions .inline-form .btn {
        width: 100%;
    }

    .search-row {
        grid-template-columns: 1fr !important;
    }

    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 720px;
    }
}


/* Set 11: user/team management */
.form-panel h3 {
    margin-top: 18px;
}

.form-panel h3:first-child {
    margin-top: 0;
}


/* Set 12: status controls */
.status-form {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    flex-wrap: nowrap;
}

.status-select {
    width: auto;
    min-width: 130px;
    margin-top: 0 !important;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
}

.status-card {
    margin-bottom: 14px;
}

.wide-status-form {
    justify-content: flex-end;
}

.status-inline-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border: 1px solid #dbeafe;
    background: #eff6ff;
    color: #1e3a8a;
    border-radius: 18px;
    padding: 14px;
    margin-bottom: 16px;
}

@media (max-width: 760px) {
    .status-form,
    .wide-status-form,
    .status-inline-panel {
        width: 100%;
        align-items: stretch;
        flex-direction: column;
    }

    .status-select,
    .status-form .btn {
        width: 100%;
    }
}


/* Set 13: multi-company */
.company-select-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, .8fr);
    gap: 14px;
    align-items: end;
    border: 1px solid #dbeafe;
    background: #eff6ff;
    border-radius: 22px;
    padding: 16px;
    margin-bottom: 18px;
}

.company-select-panel label {
    margin-bottom: 0;
}

.company-check-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.company-check-card {
    display: grid !important;
    grid-template-columns: 24px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: 18px;
    padding: 14px;
    margin: 0 !important;
}

.company-check-card input[type="checkbox"] {
    margin-top: 2px !important;
}

.company-check-card small {
    display: block;
    margin-top: 4px;
    color: #64748b;
    font-weight: 400;
    line-height: 1.35;
}

@media (max-width: 760px) {
    .company-select-panel,
    .company-check-grid {
        grid-template-columns: 1fr !important;
    }
}
