:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-primary-light: #eff6ff;
    --color-bg: #f3f5f9;
    --color-surface: #ffffff;
    --color-text: #1e2530;
    --color-muted: #6b7280;
    --color-border: #e4e8ef;
    --color-success: #16a34a;
    --color-danger: #dc2626;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow: 0 2px 8px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.08);
    --container-max: 1100px;
    --form-max: 620px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: "Segoe UI", "Noto Sans Thai", "Sarabun", Tahoma, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.65;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 24px 20px 64px;
}

.container-narrow {
    max-width: var(--form-max);
}

/* ---------- Header ---------- */
.site-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.site-header-inner {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.brand {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}
.brand-logo {
    height: 32px;
    width: auto;
    display: block;
}
@media (max-width: 640px) {
    .brand-logo { height: 26px; }
}
.site-header nav {
    display: flex;
    align-items: center;
    gap: 18px;
}
.site-header nav a {
    color: var(--color-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.15s ease;
}
.site-header nav a:hover { color: var(--color-primary); }

.site-footer {
    text-align: center;
    color: var(--color-muted);
    font-size: 0.82rem;
    padding: 24px 20px;
}

/* ---------- Typography ---------- */
h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 6px;
    letter-spacing: -0.01em;
}
h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0 0 14px;
}
.subheading {
    color: var(--color-muted);
    font-size: 0.95rem;
    margin: 0 0 20px;
}

/* ---------- Card / layout ---------- */
.page-form {
    max-width: var(--form-max);
    margin: 0 auto;
}
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
}

/* ---------- Forms ---------- */
label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    margin-top: 18px;
    font-size: 0.9rem;
    color: var(--color-text);
}
label:first-child { margin-top: 0; }
label .optional { font-weight: 400; color: var(--color-muted); }
label .required { color: var(--color-danger); }

input[type="text"],
input[type="tel"],
input[type="password"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: #fff;
    color: var(--color-text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea { resize: vertical; min-height: 110px; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

input[type="file"] {
    padding: 9px 12px;
    cursor: pointer;
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 38px;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 22px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--color-primary);
    color: #fff;
    font-size: 0.98rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: var(--color-primary-dark); }
.btn:active { transform: translateY(1px); }
.btn-block { width: 100%; }
.btn-secondary { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; }
.btn-danger { background: var(--color-danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 7px 14px; font-size: 0.85rem; }

.actions { margin-top: 22px; }

/* ---------- Alerts ---------- */
.alert {
    padding: 13px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    font-size: 0.92rem;
    border: 1px solid transparent;
}
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.alert-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}
.badge-new { background: #dbeafe; color: #1e40af; }
.badge-ack { background: #fef9c3; color: #854d0e; }
.badge-progress { background: #ffedd5; color: #9a3412; }
.badge-resolved { background: #dcfce7; color: #166534; }

.status-dot { display: inline-block; }
.status-dot.ok { color: var(--color-success); font-weight: 600; }
.status-dot.pending { color: var(--color-muted); font-weight: 600; }

/* ---------- Ticket list ---------- */
.ticket-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding: 16px 4px;
    border-bottom: 1px solid var(--color-border);
    text-decoration: none;
    color: inherit;
    transition: background 0.12s ease;
    border-radius: var(--radius-sm);
}
.ticket-item:hover { background: var(--color-bg); }
.ticket-item:last-child { border-bottom: none; }
.ticket-item-main { flex: 1; min-width: 0; }
.ticket-item-title { font-weight: 600; margin: 0 0 4px; }
.ticket-item-meta { font-size: 0.85rem; color: var(--color-muted); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Detail grid (สถานที่/แผนก/ผู้แจ้ง/วันที่ ในหน้า update.php) ---------- */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 16px;
    margin: 12px 0;
}
.detail-item {
    font-size: 0.95rem;
    overflow-wrap: break-word;
}
.detail-item.hint {
    font-size: 0.84rem;
    color: var(--color-muted);
    margin-top: 0;
}

/* ---------- Photos ---------- */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 10px;
    margin-top: 12px;
}
.photo-grid img {
    width: 100%;
    height: 96px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    transition: opacity 0.15s ease;
}
.photo-grid a:hover img { opacity: 0.85; }

/* ---------- Tables (responsive scroll) ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
table th, table td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}
table th { color: var(--color-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }

.hint { color: var(--color-muted); font-size: 0.84rem; margin-top: 6px; line-height: 1.5; }
.hint-danger { color: var(--color-danger); font-weight: 600; }

/* ---------- Status log ---------- */
.status-log { list-style: none; padding: 0; margin: 12px 0 0; }
.status-log li {
    padding: 10px 0;
    border-bottom: 1px dashed var(--color-border);
    font-size: 0.9rem;
}
.status-log li:last-child { border-bottom: none; }

/* ---------- Filters / top actions ---------- */
.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.filter-bar select,
.filter-bar input[type="date"] { width: auto; min-width: 160px; }

.top-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    flex-wrap: wrap;
    gap: 12px;
}

/* ---------- Language switcher ---------- */
.lang-switch {
    display: inline-flex;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    overflow: hidden;
    font-size: 0.82rem;
    background: var(--color-surface);
}
.lang-switch a {
    padding: 6px 14px;
    text-decoration: none;
    color: var(--color-muted);
    font-weight: 600;
    transition: background 0.12s ease, color 0.12s ease;
}
.lang-switch a.active {
    background: var(--color-primary);
    color: #fff;
}

/* ---------- Status buttons (update.php) ---------- */
.status-btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}
.status-btn {
    flex: 1 1 auto;
    min-width: 140px;
    color: #1e2530;
    font-weight: 600;
}
.status-btn.badge-new { background: #dbeafe; }
.status-btn.badge-new:hover { background: #bfdbfe; }
.status-btn.badge-ack { background: #fef9c3; }
.status-btn.badge-ack:hover { background: #fef08a; }
.status-btn.badge-progress { background: #ffedd5; }
.status-btn.badge-progress:hover { background: #fed7aa; }
.status-btn.badge-resolved { background: #dcfce7; }
.status-btn.badge-resolved:hover { background: #bbf7d0; }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-box {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow-lg);
}
.modal-box h2 { margin-top: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .container { padding: 16px 14px 48px; }
    .card { padding: 18px; border-radius: var(--radius); }
    h1 { font-size: 1.3rem; }
    .site-header-inner { padding: 12px 16px; }
    table { min-width: 480px; }
}

@media (min-width: 641px) and (max-width: 900px) {
    .container { padding: 24px 24px 56px; }
}

@media (min-width: 901px) {
    .card { padding: 28px; }
}
