@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg: #f8f9fb;
    --surface: #ffffff;
    --border: #e8eaed;
    --border-focus: #4a6cf7;
    --text: #1a1d26;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --primary: #4a6cf7;
    --primary-hover: #3b5de7;
    --primary-light: #eef1fe;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --success: #10b981;
    --success-light: #ecfdf5;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --info: #6366f1;
    --info-light: #eef2ff;
    --radius: 10px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.08);
    --transition: 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ─── Container ─── */
.container {
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    background: var(--surface);
    padding: 40px;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.container.wide {
    max-width: 1100px;
}

/* ─── Page Header ─── */
.page-header {
    text-align: center;
    margin-bottom: 32px;
}

.page-header .icon {
    width: 48px;
    height: 48px;
    background: var(--primary-light);
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin-bottom: 16px;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
    letter-spacing: -0.3px;
}

.page-header p {
    font-size: 14px;
    color: var(--text-muted);
}

/* ─── Forms ─── */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

input,
textarea,
select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.1);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

input[readonly] {
    background: var(--bg);
    color: var(--text-secondary);
    cursor: default;
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    line-height: 1.4;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    width: 100%;
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(74, 108, 247, 0.3);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    width: 100%;
}

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

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background: var(--bg);
    color: var(--text);
}

.btn-group {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.btn-group .btn {
    flex: 1;
}

/* ─── Checkbox Grid ─── */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 400;
    color: var(--text);
    transition: all var(--transition);
    text-transform: none;
}

.checkbox-label:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

/* ─── Alerts / Flash ─── */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 20px;
}

.alert-error {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-success {
    background: var(--success-light);
    color: #065f46;
    border: 1px solid #a7f3d0;
}

/* ─── Table ─── */
.data-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead {
    background: var(--bg);
}

.data-table th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 12px 14px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.data-table tbody tr {
    transition: background var(--transition);
}

.data-table tbody tr:hover {
    background: var(--bg);
}

.data-table .empty-state {
    padding: 48px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* ─── Status Badge ─── */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-warning {
    background: var(--warning-light);
    color: #92400e;
}

.badge-info {
    background: var(--info-light);
    color: #3730a3;
}

.badge-success {
    background: var(--success-light);
    color: #065f46;
}

/* status class mapping */
.status-รอดำเนินการ {
    background: var(--warning-light);
    color: #92400e;
}

.status-กำลังดำเนินการ {
    background: var(--info-light);
    color: #3730a3;
}

.status-เสร็จสิ้น {
    background: var(--success-light);
    color: #065f46;
}

/* ─── Status Select (inline in table) ─── */
.status-select {
    width: auto;
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    text-align: center;
}

.status-select.status-รอดำเนินการ {
    background: var(--warning-light);
    color: #92400e;
}

.status-select.status-กำลังดำเนินการ {
    background: var(--info-light);
    color: #3730a3;
}

.status-select.status-เสร็จสิ้น {
    background: var(--success-light);
    color: #065f46;
}

/* ─── Edit Project: Section Cards ─── */
.edit-header {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    color: #fff;
    padding: 28px 32px;
    border-radius: 12px 12px 0 0;
    margin: -40px -40px 32px -40px;
}

.edit-header h1 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
    color: #fff;
}

.edit-header p {
    font-size: 13px;
    color: #94a3b8;
}

.edit-header .project-id {
    display: inline-block;
    background: rgba(255,255,255,0.15);
    color: #e2e8f0;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 8px;
}

.section-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    background: #fafbfc;
}

.section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

@media (max-width: 768px) {
    .edit-header {
        margin: -24px -16px 24px -16px;
        border-radius: 0;
        padding: 20px 16px;
    }

    .form-grid-2 {
        grid-template-columns: 1fr;
    }
}

/* ─── Utility ─── */
.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.hidden {
    display: none;
}

.mt-8 {
    margin-top: 8px;
}

.mt-12 {
    margin-top: 12px;
}

.mt-16 {
    margin-top: 16px;
}

.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
}

.toolbar .btn {
    width: auto;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    body {
        padding: 0;
        align-items: flex-start;
    }

    .container {
        padding: 24px 16px;
        border-radius: 0;
        border: none;
        box-shadow: none;
        min-height: 100vh;
    }

    .container.wide {
        max-width: 100%;
    }

    .page-header {
        margin-bottom: 24px;
    }

    .page-header h1 {
        font-size: 20px;
    }

    /* Larger touch targets */
    input,
    textarea,
    select {
        padding: 12px 14px;
        font-size: 16px;
        /* prevents iOS zoom */
    }

    .btn {
        padding: 14px 20px;
        font-size: 15px;
        min-height: 48px;
    }

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

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

    .checkbox-label {
        padding: 10px;
        font-size: 13px;
        min-height: 44px;
    }

    .checkbox-label input[type="checkbox"] {
        width: 20px;
        height: 20px;
    }

    .toolbar {
        flex-direction: column;
        gap: 8px;
    }

    .toolbar .btn {
        width: 100%;
    }

    .form-group {
        margin-bottom: 16px;
    }

    label {
        font-size: 12px;
        margin-bottom: 4px;
    }

    .btn-group {
        flex-direction: column;
        gap: 8px;
    }

    /* ── Table → Card on mobile ── */
    .data-table-wrap {
        overflow-x: visible;
        border: none;
        border-radius: 0;
    }

    .data-table thead {
        display: none;
    }

    .data-table {
        display: block;
        width: 100%;
        min-width: 0;
    }

    .data-table tbody {
        display: block;
        width: 100%;
    }

    .data-table tbody tr {
        display: block;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 12px;
        margin-bottom: 12px;
        padding: 4px 0;
        box-shadow: var(--shadow-sm);
        width: 100%;
    }

    .data-table tbody tr:hover {
        background: var(--surface);
    }

    .data-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 10px 16px;
        border-bottom: 1px solid var(--border);
        font-size: 13px;
        white-space: normal !important;
        width: 100%;
        box-sizing: border-box;
    }

    .data-table td:last-child {
        border-bottom: none;
    }

    .data-table td::before {
        content: attr(data-label);
        font-size: 10px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--text-muted);
        white-space: nowrap;
        flex-shrink: 0;
        min-width: 72px;
    }

    .data-table td[data-label=""] {
        justify-content: flex-end;
        padding: 12px 16px;
    }

    .data-table td[data-label=""]::before {
        display: none;
    }

    .data-table .empty-state {
        display: block;
        padding: 32px 16px;
    }

    /* status select on mobile */
    .status-select {
        font-size: 12px;
        padding: 5px 10px;
    }

    /* section card on mobile */
    .section-card {
        padding: 16px;
    }
}