:root {
    --color-bg: #f3f4f6;
    --color-surface: #ffffff;
    --color-text: #1a1a1a;
    --color-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-success: #059669;
    --color-error: #dc2626;
    --color-error-bg: #fde8e8;
    --color-success-bg: #ecfdf5;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --radius: 8px;
    --radius-pill: 999px;
}

* {
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    margin: 0;
    padding: 0;
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.5;
}

.app-shell {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1rem 4rem;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--color-border);
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
    text-decoration: none;
}

.app-brand i {
    color: var(--color-primary);
}

.app-header nav {
    display: flex;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    border: none;
}

.app-header nav a {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius-pill);
    color: var(--color-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.app-header nav a:hover {
    background: #e8eefc;
    color: var(--color-primary);
    text-decoration: none;
}

h1 {
    font-size: 1.35rem;
    margin: 0 0 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

h1 i {
    color: var(--color-primary);
}

.page-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.25rem;
}

.auth-card {
    max-width: 420px;
    margin: 2rem auto 0;
}

label {
    display: block;
    margin-top: 1rem;
    font-weight: 600;
    font-size: 0.9rem;
}

label:first-child,
.field:first-child label {
    margin-top: 0;
}

label i {
    margin-right: 0.35rem;
    color: var(--color-muted);
    width: 1rem;
    text-align: center;
}

input[type="email"],
input[type="password"],
input[type="text"],
select,
.form-control {
    width: 100%;
    padding: 0.55rem 0.75rem;
    margin-top: 0.35rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.95rem;
    background: var(--color-surface);
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0 1rem;
}

.field {
    min-width: 0;
}

.datetime-field {
    position: relative;
}

.datetime-field .flatpickr-input.form-control {
    cursor: pointer;
}

.datetime-field input[type="hidden"] {
    display: none;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 1.25rem;
    padding: 0.55rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

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

.btn-primary:hover {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}

.btn-secondary:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.results-table .btn,
.inline-form .btn {
    margin-top: 0;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    font-weight: normal;
}

.checkbox input {
    width: auto;
    margin: 0;
}

.inline-form {
    margin-top: 0.5rem;
}

.flash {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.flash i {
    margin-top: 0.1rem;
    flex-shrink: 0;
}

.flash.error {
    background: var(--color-error-bg);
    color: #9b1c1c;
}

.flash.error i {
    color: var(--color-error);
}

.flash.success {
    background: var(--color-success-bg);
    color: #065f46;
}

.flash.success i {
    color: var(--color-success);
}

.note {
    margin-top: 1rem;
    font-size: 0.875rem;
    color: var(--color-muted);
}

.note a {
    color: var(--color-primary);
    text-decoration: none;
}

.note a:hover {
    text-decoration: underline;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.results-header p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--color-muted);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

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

.results-table {
    width: max-content;
    border-collapse: collapse;
    table-layout: fixed;
}

.results-table th,
.results-table td {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.results-table th {
    background: #f9fafb;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.results-table .col-date {
    width: 11.5rem;
}

.results-table .col-route {
    width: 12rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.results-table .col-state {
    width: 3.5rem;
    text-align: center;
}

.results-table .col-action {
    width: 7.5rem;
}

.status-ok {
    color: var(--color-success);
}

.status-fail {
    color: var(--color-error);
}

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay.open {
    display: flex;
}

.modal-panel {
    background: var(--color-surface);
    border-radius: var(--radius);
    max-width: 720px;
    width: 100%;
    max-height: 85vh;
    overflow: auto;
    padding: 1.25rem;
    position: relative;
    box-shadow: var(--shadow-md);
}

.modal-panel h2 {
    margin: 0 2rem 0.75rem 0;
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-panel h2 i {
    color: var(--color-primary);
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    margin: 0;
    padding: 0.25rem;
    color: var(--color-muted);
    border-radius: 4px;
}

.modal-close:hover {
    background: #f3f4f6;
    color: var(--color-text);
}

.modal-section {
    margin-top: 1rem;
}

.modal-section h3 {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--color-text);
}

.modal-section h3 i {
    color: var(--color-primary);
}

.modal-section table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.modal-section th,
.modal-section td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
}

.modal-section th {
    background: #f9fafb;
    font-weight: 600;
}

.modal-section tbody tr:last-child td,
.modal-section tbody tr:last-child th {
    border-bottom: none;
}

.kv-table td:first-child {
    font-weight: 600;
    width: 11rem;
    white-space: nowrap;
    vertical-align: top;
}

.kv-table td:last-child {
    word-break: break-word;
}

.stages-table {
    table-layout: fixed;
}

.stages-table .col-stage-name {
    width: 42%;
}

.stages-table .col-stage-status {
    width: 18%;
}

.stages-table .col-stage-reason {
    width: 40%;
}

.stages-table td:first-child {
    word-break: break-word;
}

.progress-list {
    max-height: 280px;
    overflow-y: auto;
    scroll-behavior: smooth;
    font-size: 0.875rem;
    margin-top: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 0.5rem;
    background: #f9fafb;
}

.progress-list .progress-line {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.2rem 0;
}

.progress-list .progress-line i {
    width: 1rem;
    text-align: center;
    flex-shrink: 0;
    color: var(--color-muted);
}

.progress-list .error {
    color: var(--color-error);
}

.progress-list .error i {
    color: var(--color-error);
}

.session-expired-error {
    color: var(--color-error);
    margin: 0 0 0.75rem;
}

#detail-redirect-countdown {
    margin: 0;
    color: var(--color-muted);
    font-size: 0.9rem;
}

#export-download a {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--color-primary);
    font-weight: 500;
    text-decoration: none;
}

#export-download a:hover {
    text-decoration: underline;
}

.scroll-top-fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    box-shadow: var(--shadow-md);
    transition: background 0.15s, transform 0.15s;
}

.scroll-top-fab:hover {
    background: var(--color-primary-hover);
    transform: translateY(-2px);
}
