* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: #f4f6fb;
    color: #111827;
    font-size: 16px;
}
a { color: #0d6efd; text-decoration: none; }
a:hover { text-decoration: underline; }
.container { max-width: 1540px; margin: 0 auto; padding: 0 24px; }
.page { padding-top: 34px; padding-bottom: 60px; }
.topbar {
    background: #fff;
    border-bottom: 1px solid #d8dde7;
    box-shadow: 0 1px 8px rgba(15, 23, 42, .08);
}
.nav-container { height: 64px; display: flex; align-items: center; gap: 28px; }
.brand { font-weight: 800; font-size: 24px; color: #000; }
.nav-links, .nav-right { display: flex; align-items: center; gap: 22px; }
.nav-links a, .nav-right a, .link-button { color: #374151; font-size: 18px; }
.nav-right { margin-left: auto; }
.inline-form { display: inline; }
.link-button { border: 0; background: transparent; cursor: pointer; padding: 0; font-family: inherit; }

h1 { font-size: 34px; margin: 0 0 24px; }
h2 { margin: 0 0 12px; }
label { display: block; margin: 12px 0 6px; font-size: 18px; }
.form-control {
    width: 100%;
    min-height: 42px;
    padding: 8px 12px;
    border: 1px solid #cfd6df;
    border-radius: 6px;
    font-size: 18px;
    background: #fff;
}
.form-control:focus { outline: 3px solid rgba(13, 110, 253, .14); border-color: #8ab8ff; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 6px;
    min-height: 38px;
    padding: 8px 13px;
    font-size: 16px;
    cursor: pointer;
    color: #fff;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.98); }
.btn-primary { background: #0d6efd; }
.btn-success { background: #198754; }
.btn-secondary { background: #6c757d; }
.btn-danger { background: #dc3545; }
.btn-info { background: #0dcaf0; color: #06232a; }
.btn-light { background: #eef2f7; color: #111827; border-color: #cbd5e1; }
.btn-outline-danger { background: #fff; color: #dc3545; border-color: #dc3545; }
.btn.full { width: 100%; margin-top: 20px; }
.btn.square { width: 44px; padding: 7px 0; }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; }
.alert.success { background: #e7f8ef; color: #0f5132; border: 1px solid #badbcc; }
.alert.danger { background: #fff1f2; color: #842029; border: 1px solid #f5c2c7; }
.validation { color: #dc3545; font-size: 14px; margin: 4px 0 8px; }

.auth-wrap { min-height: 72vh; display: flex; align-items: center; justify-content: center; }
.auth-card {
    width: min(600px, 100%);
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 14px;
    padding: 36px 32px;
}
.auth-card h1 { text-align: center; }
.check-row { display: flex; align-items: center; gap: 10px; margin-top: 20px; }
.check-row input { width: 20px; height: 20px; }
.center { text-align: center; }
.muted { color: #5b6472; }
.small { font-size: 13px; }

.panel {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 20px;
}
.panel.narrow { max-width: 650px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.site-form { display: flex; align-items: center; gap: 10px; min-width: 460px; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #d7dee8;
}
.data-table th, .data-table td {
    border: 1px solid #d7dee8;
    padding: 12px 10px;
    text-align: left;
    vertical-align: middle;
    font-size: 18px;
}
.data-table th { font-weight: 800; background: #fff; }
.actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.nowrap { white-space: nowrap; }

.sub-card, .section-card {
    border: 1px solid #cfd6df;
    border-radius: 12px;
    margin: 22px 0;
    padding: 14px 18px;
    background: #fff;
}
.sub-card-title { font-size: 20px; font-weight: 800; padding: 8px 10px 14px; border-bottom: 1px solid #d1d5db; margin: -4px -8px 14px; }
.grid { display: grid; gap: 20px 28px; }
.grid.three { grid-template-columns: repeat(3, 1fr); }
.section-header { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.section-title { font-weight: 600; }
.entry-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.entry-table th, .entry-table td { border: 1px solid #d7dee8; padding: 10px; vertical-align: middle; }
.entry-table th { text-align: left; font-size: 18px; }
.entry-table th:nth-child(1) { width: 28%; }
.entry-table th:nth-child(2) { width: 16%; }
.entry-table th:nth-child(3) { width: 17%; }
.entry-table th:nth-child(4) { width: 16%; }
.entry-table th:nth-child(5) { width: 7%; }
.entry-table th:nth-child(6) { width: 9%; }
.entry-table th:nth-child(7) { width: 5%; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.right { text-align: right !important; }
.tiny-check { font-size: 13px; display: inline-flex; align-items: center; gap: 4px; margin: 7px 0 0; color: #334155; }
.tiny-check input { width: 13px; height: 13px; }
.voice-input { display: flex; gap: 6px; }
.voice-input .desc { flex: 1; }
.mic { min-width: 54px; }
.listening { border-color: #198754 !important; box-shadow: 0 0 0 3px rgba(25, 135, 84, .15); }
.add-row { margin-top: 18px; }
.grand-box { margin-top: 22px; display: flex; justify-content: flex-end; align-items: center; gap: 18px; }
.grand-box h2 { font-size: 26px; }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.details-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 40px; margin: 20px 0 30px; }
.details-grid p { font-size: 18px; margin: 8px 0; }
.section-title-view { margin: 22px 0 10px; }
.detail-table td, .detail-table th { text-align: left; }
.detail-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 26px; }

@media (max-width: 900px) {
    .container { padding: 0 14px; }
    .nav-container { height: auto; padding-top: 12px; padding-bottom: 12px; flex-wrap: wrap; }
    .nav-right { margin-left: 0; }
    .page-head, .site-form, .grand-box, .detail-head, .detail-bottom { align-items: stretch; flex-direction: column; }
    .site-form { min-width: 0; width: 100%; }
    .grid.three, .details-grid { grid-template-columns: 1fr; gap: 8px; }
    .data-table, .entry-table { display: block; overflow-x: auto; }
    .panel { padding: 14px; }
}

.site-rate-table th:nth-child(1) { width: 18%; }
.site-rate-table th:nth-child(2) { width: 56%; }
.site-rate-table th:nth-child(3) { width: 26%; }
.rate-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.rate-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 999px;
    background: #eef2ff;
    color: #1e3a8a;
    font-size: 14px;
    font-weight: 700;
}
.rate-delete {
    border: 0;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #dc3545;
    color: #fff;
    line-height: 18px;
    cursor: pointer;
    padding: 0;
}
.rate-form { display: grid; grid-template-columns: minmax(130px, 1fr) minmax(120px, 160px) auto; gap: 8px; align-items: center; margin-top: 10px; }
.rate-cell { min-width: 220px; }
.rate-cell .form-control { margin-bottom: 6px; }
.rate-cell .rate { margin-bottom: 0; }
.rate[readonly] { background: #f8fafc; color: #475569; }

@media (max-width: 900px) {
    .rate-form { grid-template-columns: 1fr; }
}

.btn-sm-space { margin-top: 10px; }
.form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    margin-top: 22px;
}
.form-actions.left { justify-content: flex-start; }
.site-create-form .sub-card { margin-top: 18px; }
.mini-rate-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
    background: #fff;
}
.mini-rate-table th,
.mini-rate-table td {
    border: 1px solid #e5e7eb;
    padding: 7px 8px;
    font-size: 14px;
}
.mini-rate-table th { background: #f8fafc; font-weight: 800; }
.manage-rate-table th:nth-child(1) { width: 50%; }
.manage-rate-table th:nth-child(2) { width: 30%; }
.manage-rate-table th:nth-child(3) { width: 20%; }
.rate-name-input,
.rate-amount-input { max-width: 100%; }

@media (max-width: 900px) {
    .form-actions { flex-direction: column; align-items: stretch; }
}

/* Global mic-enabled text fields */
html { -webkit-text-size-adjust: 100%; }
img { max-width: 100%; height: auto; }
.container { width: 100%; }

.voice-field,
.voice-input {
    position: relative;
    display: block;
    width: 100%;
}

.voice-field .form-control,
.voice-input .form-control {
    padding-right: 50px;
}

button.voice-mic-button,
.voice-input .mic {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    width: 34px;
    min-width: 34px;
    height: 34px;
    min-height: 34px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #0d6efd;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
}

button.voice-mic-button:hover,
.voice-input .mic:hover {
    background: #eaf2ff;
    border-color: #8ab8ff;
}

button.voice-mic-button svg,
.voice-input .mic svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.voice-field.is-listening .form-control,
.voice-input.is-listening .form-control,
.form-control.listening {
    border-color: #198754 !important;
    box-shadow: 0 0 0 3px rgba(25, 135, 84, .15);
}

button.voice-mic-button.is-listening,
.voice-input.is-listening .mic {
    background: #e7f8ef;
    border-color: #198754;
    color: #198754;
}

@media (max-width: 1200px) {
    .container { max-width: 100%; }
    .grid.three { gap: 16px; }
    .data-table th,
    .data-table td,
    .entry-table th,
    .entry-table td { font-size: 16px; }
}

@media (max-width: 900px) {
    h1 { font-size: 28px; }
    h2 { font-size: 22px; }
    label { font-size: 16px; }
    .brand { font-size: 22px; }
    .nav-container { gap: 12px; }
    .nav-links,
    .nav-right {
        width: 100%;
        flex-wrap: wrap;
        gap: 12px 18px;
    }
    .entry-table { min-width: 940px; }
    .data-table { min-width: 680px; }
    .manage-rate-table { min-width: 620px; }
    .section-card,
    .sub-card { padding: 14px; }
    .section-header { align-items: stretch; flex-direction: column; }
    .section-header .btn { width: 100%; }
}

@media (max-width: 640px) {
    body { font-size: 15px; }
    .container { padding: 0 10px; }
    .page { padding-top: 18px; padding-bottom: 36px; }
    .auth-wrap { min-height: auto; padding: 14px 0; }
    .auth-card,
    .panel {
        border-radius: 10px;
        padding: 14px;
    }
    .sub-card,
    .section-card {
        margin: 14px 0;
        padding: 12px;
        border-radius: 10px;
    }
    .sub-card-title { font-size: 18px; }
    .form-control {
        min-height: 44px;
        font-size: 16px;
    }
    .btn {
        width: 100%;
        min-height: 42px;
        font-size: 15px;
    }
    .btn.square { width: 100%; }
    .form-actions,
    .actions,
    .grand-box {
        width: 100%;
        align-items: stretch;
    }
    .grand-box h2 { font-size: 21px; }
    .data-table,
    .entry-table {
        -webkit-overflow-scrolling: touch;
    }
    .rate-cell { min-width: 190px; }
}

/* Full responsive layout improvements */
html, body { max-width: 100%; overflow-x: hidden; }
input, select, textarea, button { font: inherit; min-width: 0; }
.form-control { max-width: 100%; }
.panel, .sub-card, .section-card, .auth-card { max-width: 100%; }

.actions .inline-form { display: inline-flex; }
.empty-cell { text-align: center; color: #5b6472; }
.operator { text-align: center !important; color: #64748b; width: 1%; }

@media (max-width: 1024px) {
    .container { max-width: 100%; padding-left: 16px; padding-right: 16px; }
    .page { padding-top: 24px; }
    .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .details-grid { grid-template-columns: 1fr 1fr; gap: 20px; }
}

@media (max-width: 900px) {
    h1 { font-size: 25px; line-height: 1.2; margin-bottom: 14px; }
    h2 { font-size: 20px; }
    .container { padding-left: 12px; padding-right: 12px; }
    .page { padding-top: 16px; padding-bottom: 32px; }

    .topbar { position: static; }
    .nav-container {
        height: auto;
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
        padding-top: 12px;
        padding-bottom: 12px;
    }
    .brand { font-size: 22px; }
    .nav-links,
    .nav-right {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        margin-left: 0;
    }
    .nav-links a,
    .nav-right a,
    .nav-right .link-button {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 38px;
        border: 1px solid #d7dee8;
        border-radius: 8px;
        background: #f8fafc;
        padding: 7px 8px;
        font-size: 15px;
        text-align: center;
    }
    .nav-right .inline-form { display: block; width: 100%; }
    .nav-right .inline-form .link-button { width: 100%; }

    .page-head,
    .detail-head,
    .detail-bottom,
    .grand-box,
    .form-actions,
    .section-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .page-head .btn,
    .detail-head .btn,
    .detail-bottom .btn,
    .grand-box .btn,
    .form-actions .btn,
    .section-header .btn { width: 100%; }

    .grid.three,
    .details-grid { grid-template-columns: 1fr; gap: 10px; }
    .panel { padding: 12px; border-radius: 10px; }
    .sub-card,
    .section-card { padding: 12px; margin: 14px 0; }
    .sub-card-title { font-size: 17px; padding-bottom: 10px; }

    .voice-field .form-control,
    .voice-input .form-control { padding-right: 48px; }

    .responsive-table,
    .responsive-table thead,
    .responsive-table tbody,
    .responsive-table tfoot,
    .responsive-table tr,
    .responsive-table th,
    .responsive-table td {
        display: block;
        width: 100%;
        min-width: 0 !important;
    }

    .responsive-table {
        border: 0;
        background: transparent;
        overflow: visible;
    }
    .responsive-table thead { display: none; }
    .responsive-table tbody tr,
    .responsive-table tfoot tr {
        background: #fff;
        border: 1px solid #d7dee8;
        border-radius: 12px;
        box-shadow: 0 1px 8px rgba(15, 23, 42, .06);
        margin: 0 0 12px;
        padding: 10px;
    }
    .responsive-table td,
    .responsive-table th {
        border: 0 !important;
        padding: 8px 0 !important;
        font-size: 15px;
        text-align: left !important;
        white-space: normal;
    }
    .responsive-table td[data-label] {
        display: grid;
        grid-template-columns: minmax(105px, 36%) minmax(0, 1fr);
        gap: 8px;
        align-items: start;
        border-bottom: 1px solid #eef2f7 !important;
    }
    .responsive-table td[data-label]::before {
        content: attr(data-label);
        font-weight: 800;
        color: #334155;
    }
    .responsive-table td:last-child { border-bottom: 0 !important; }
    .responsive-table .actions {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .responsive-table .actions::before { margin-bottom: 2px; }
    .responsive-table .actions .btn,
    .responsive-table .actions .inline-form,
    .responsive-table .actions .inline-form .btn { width: 100%; }

    .entry-table,
    .data-table,
    .manage-rate-table { min-width: 0 !important; overflow: visible; }
    .measurement-entry-table tbody tr { padding-top: 12px; }
    .measurement-entry-table td[data-label] { grid-template-columns: 1fr; gap: 5px; }
    .measurement-entry-table .operator { display: none !important; }
    .section-total-label { display: none !important; }
    .measurement-entry-table tfoot tr {
        display: grid;
        grid-template-columns: 1fr;
    }
    .measurement-entry-table tfoot td[data-label] {
        display: flex;
        justify-content: space-between;
        gap: 10px;
        font-weight: 800;
    }

    .rate-cell { min-width: 0; }
    .btn.square { width: 100%; }
    .grand-box h2 { font-size: 20px; text-align: center; }
}

@media (max-width: 480px) {
    body { font-size: 14px; }
    .container { padding-left: 8px; padding-right: 8px; }
    .auth-card, .panel { padding: 10px; }
    .nav-links,
    .nav-right { grid-template-columns: 1fr; }
    .btn { min-height: 40px; padding: 8px 10px; font-size: 14px; }
    .form-control { min-height: 42px; font-size: 15px; }
    label { font-size: 15px; }
    .responsive-table tbody tr,
    .responsive-table tfoot tr { padding: 9px; border-radius: 10px; }
    .responsive-table td[data-label] { grid-template-columns: 1fr; gap: 4px; }
    .responsive-table td[data-label]::before { font-size: 13px; }
    button.voice-mic-button,
    .voice-input .mic { right: 6px; width: 32px; min-width: 32px; height: 32px; min-height: 32px; }
}

@media (max-width: 900px) {
    .responsive-table td:not([data-label]):empty { display: none; }
}
