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

:root {
    color-scheme: light;
    --bg: #f4efe7;
    --bg-accent: #e4f1ef;
    --surface: #ffffff;
    --surface-muted: #f0ebe2;
    --text: #1f2328;
    --muted: #6b6a63;
    --accent: #2b5b5e;
    --accent-strong: #1f4446;
    --accent-soft: #d6ebe8;
    --warning: #f2b33d;
    --danger: #d4564d;
    --danger-strong: #c63a2f;
    --success: #1f7a5a;
    --shadow: none;
    font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: radial-gradient(circle at top, var(--bg-accent), var(--bg) 60%);
    color: var(--text);
    min-height: 100vh;
}

a {
    color: inherit;
}

h1,
h2,
h3 {
    margin: 0 0 0.5rem 0;
    letter-spacing: -0.02em;
}

h1:focus,
h1:focus-visible {
    outline: none;
}

p {
    margin: 0.25rem 0 0.75rem 0;
}

.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 2.5rem;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(31, 35, 40, 0.08);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: var(--surface);
    display: grid;
    place-items: center;
    overflow: hidden;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.brand-name {
    font-weight: 700;
}

.brand-subtitle {
    font-size: 0.85rem;
    color: var(--muted);
}

.app-nav {
    display: flex;
    gap: 1.75rem;
    font-weight: 600;
}

.app-nav a {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    text-decoration: none;
    padding-bottom: 0.2rem;
    border-bottom: 2px solid transparent;
    font-size: 1.05rem;
}

.app-nav a.active {
    border-color: var(--accent);
}

.nav-icon {
    display: inline-flex;
}

.nav-icon svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    display: block;
}

.app-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pill {
    background: var(--accent-soft);
    color: var(--accent-strong);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.app-main {
    flex: 1;
    padding: 2rem 2.5rem 3rem;
}

.app-footer {
    padding: 1.5rem 2.5rem 2.5rem;
    color: var(--muted);
    font-size: 0.85rem;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-subtitle {
    color: var(--muted);
    max-width: 640px;
}

.page-actions {
    display: flex;
    gap: 0.75rem;
}

.summary-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.summary-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--surface);
    border-radius: 16px;
    padding: 0.9rem 1.1rem;
    box-shadow: var(--shadow);
    border: 1px solid rgba(31, 35, 40, 0.08);
}

.summary-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.7);
}

.summary-icon svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.summary-content {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
    white-space: nowrap;
}

.summary-label {
    font-size: 1.15rem;
    font-weight: 600;
    color: inherit;
}

.summary-label::after {
    content: ":";
    margin-left: 0.2rem;
}

.summary-value {
    font-size: 1.15rem;
    font-weight: 700;
}

.summary-total {
    background: #e7f0ef;
    color: var(--accent-strong);
    border-color: rgba(43, 91, 94, 0.25);
}

.summary-active {
    background: #e7f3ff;
    color: #1d4ed8;
    border-color: rgba(29, 78, 216, 0.2);
}

.summary-healthy {
    background: #e9f7f1;
    color: var(--success);
    border-color: rgba(31, 122, 90, 0.2);
}

.summary-alert {
    background: #fff1ea;
    color: var(--danger-strong);
    border-color: rgba(198, 58, 47, 0.2);
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.5rem;
}

.status-card {
    background: var(--surface);
    border-radius: 20px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid rgba(31, 35, 40, 0.08);
    border-left: 6px solid rgba(31, 35, 40, 0.12);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.status-card-link {
    cursor: pointer;
}

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

.status-card-warn {
    border-left-color: var(--warning);
}

.status-card-down {
    border-left-color: var(--danger-strong);
}

.status-card-unknown {
    border-left-color: rgba(107, 106, 99, 0.65);
}

.status-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.status-title-link {
    text-decoration: none;
    color: inherit;
    display: inline-block;
}

.status-card-link:hover .status-title-link {
    text-decoration: underline;
}

.status-card-body {
    display: grid;
    gap: 0.75rem;
}

.metric {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
}

.metric-label {
    color: var(--muted);
}

.metric-value {
    font-weight: 600;
}

.status-card-actions {
    margin-top: auto;
}

.card {
    background: var(--surface);
    border-radius: 20px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid rgba(31, 35, 40, 0.08);
}

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

.error-card {
    max-width: 640px;
}

.empty {
    text-align: center;
    color: var(--muted);
}

.grid-two {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.table {
    display: grid;
    gap: 0.75rem;
}

.table-row {
    display: grid;
    grid-template-columns: minmax(160px, 1.2fr) minmax(180px, 1.4fr) minmax(140px, 0.8fr) minmax(160px, 1fr);
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(31, 35, 40, 0.08);
}

.table-row.five {
    grid-template-columns: minmax(170px, 1.4fr) minmax(120px, 0.7fr) minmax(80px, 0.5fr) minmax(100px, 0.6fr) minmax(200px, 1.6fr);
}

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

.sources-table .table-row {
    grid-template-columns: 60px 250px minmax(200px, 1.2fr) minmax(240px, 1.8fr) minmax(170px, 1fr) minmax(140px, 0.8fr);
}

.table-head {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    padding-bottom: 0.5rem;
}

.table-title {
    font-weight: 600;
}

.table-cell {
    color: var(--muted);
}

.actions {
    display: flex;
    gap: 0.95rem;
    flex-wrap: wrap;
    align-items: center;
}

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

.info-label {
    color: var(--muted);
    font-size: 0.85rem;
}

.info-value {
    font-weight: 600;
}

.btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 0.6rem 1.4rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.action-btn {
    border-radius: 12px;
    padding: 0.55rem 1.2rem;
}

.action-btn.action-create {
    background: var(--accent);
}

.action-btn.action-refresh {
    background: #2563eb;
}

.action-btn.action-save {
    background: var(--success);
}

.action-btn.action-delete {
    background: var(--danger-strong);
    color: #fff;
}

.action-btn.action-cancel {
    background: #f3f4f6;
    color: var(--text);
    border: 1px solid rgba(31, 35, 40, 0.12);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn.ghost {
    background: transparent;
    color: var(--accent-strong);
    border: 1px solid rgba(31, 35, 40, 0.2);
}

.btn-icon {
    display: inline-flex;
}

.btn-icon svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    display: block;
}

.link {
    color: var(--accent-strong);
    font-weight: 600;
    text-decoration: none;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
}

.link:hover {
    text-decoration: underline;
}

.action-link {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    border: none;
    background: none;
    padding: 0;
    cursor: pointer;
    font-weight: 600;
}

.action-icon svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    display: block;
}

.action-edit {
    color: var(--accent-strong);
}

.action-play {
    color: var(--success);
}

.action-pause {
    color: #b45309;
}

.action-link.action-delete {
    color: var(--danger-strong);
}

.action-close {
    color: var(--muted);
}

.form {
    display: grid;
    gap: 1rem;
}

.auth-wrapper {
    max-width: 520px;
    margin: 3.5rem auto 0;
    padding: 0 1rem;
}

.auth-card {
    padding: 2rem;
}

.auth-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.auth-logo {
    width: 64px;
    height: 64px;
    border-radius: 18px;
}

.auth-title {
    margin: 0;
}

.auth-helper {
    color: var(--muted);
    margin: 0.25rem 0 0;
}

.field {
    display: grid;
    gap: 0.35rem;
    font-weight: 600;
}

.field-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.field-icon svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    display: block;
}

.field.inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

.input {
    border: 1px solid rgba(31, 35, 40, 0.18);
    border-radius: 12px;
    padding: 0.6rem 0.75rem;
    font-size: 0.95rem;
    font-family: inherit;
}

.checkbox {
    width: 18px;
    height: 18px;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
}

.modal-actions {
    justify-content: flex-end;
}

.table-cell.stt {
    color: var(--muted);
    text-align: center;
}

.table-head .stt {
    text-align: center;
}

.status-badge {
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-ok {
    background: rgba(31, 122, 90, 0.12);
    color: var(--success);
}

.status-warn {
    background: rgba(242, 179, 61, 0.15);
    color: #a36b06;
}

.status-down {
    background: rgba(212, 86, 77, 0.16);
    color: var(--danger-strong);
}

.status-unknown {
    background: rgba(107, 106, 99, 0.12);
    color: var(--muted);
}

.muted {
    color: var(--muted);
}

.muted.small {
    font-size: 0.8rem;
}

.validation-message {
    color: var(--danger-strong);
    font-size: 0.85rem;
}

.validation-summary {
    color: var(--danger-strong);
    font-size: 0.9rem;
}

.validation-summary ul {
    margin: 0;
    padding-left: 1.1rem;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    display: grid;
    place-items: center;
    padding: 1.5rem;
    z-index: 50;
}

.modal-card {
    width: min(540px, 100%);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.2);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.modal-text {
    margin: 0 0 1.5rem 0;
    color: var(--muted);
}

.modal-danger {
    border: 1px solid rgba(212, 86, 77, 0.3);
}

@media (max-width: 1200px) {
    .status-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .app-main {
        padding: 1.5rem;
    }

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

    .status-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .table-row {
        grid-template-columns: 1fr;
        gap: 0.35rem;
    }

    .table-head {
        display: none;
    }
}

@media (max-width: 600px) {
    .status-grid {
        grid-template-columns: 1fr;
    }
}

.clock {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.75rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 0.85rem;
    font-weight: 600;
    min-width: 105px;
}

.clock-icon svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    display: block;
}

.logout-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    border: 1px solid rgba(31, 35, 40, 0.18);
    background: var(--surface);
    color: var(--accent-strong);
    font-weight: 600;
    cursor: pointer;
}

.logout-pill:hover {
    background: var(--surface-muted);
}

.logout-icon svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    display: block;
}

/* Ẩn label mặc định trên desktop/tablet */
.sources-table .source-label {
    display: none;
}

/* Responsive cho bảng sources */

/* Mobile: Chuyển sang layout card */
@media (max-width: 767.98px) {

    /* Ẩn header bảng */
    .sources-table .table-head {
        display: none;
    }

    /* Chuyển mỗi hàng thành card */
    .sources-table .table-row {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        padding: 1rem;
        background: var(--surface-muted);
        border-radius: 12px;
        border-bottom: none;
    }

    /* Tên nguồn - hiển thị to và rõ */
    .sources-table .source-name {
        font-size: 1.1rem;
        font-weight: 700;
        color: var(--text);
        margin-bottom: 0.25rem;
    }

    /* URL, kiểu kiểm tra, trạng thái - hiển thị với label */
    .sources-table .source-url,
    .sources-table .source-type,
    .sources-table .source-status {
        display: flex;
        gap: 0.5rem;
        align-items: center;
        font-size: 0.9rem;
    }

    .sources-table .source-label {
        display: inline-block;
        font-weight: 600;
        color: var(--muted);
        min-width: 100px;
    }

    .sources-table .source-value {
        color: var(--text);
        word-break: break-all;
    }

    /* Hành động - hiển thị ngang ở cuối */
    .sources-table .actions {
        display: flex;
        gap: 0.75rem;
        flex-wrap: wrap;
        margin-top: 0.5rem;
        padding-top: 0.75rem;
        border-top: 1px solid rgba(31, 35, 40, 0.08);
    }

    /* Ẩn STT trên mobile */
    .sources-table .stt {
        display: none;
    }

    /* Stack nút bấm vertically trên mobile */
    .page-actions {
        flex-direction: column;
        width: 100%;
    }

    .page-actions .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Tablet: Tối ưu bảng */
@media (min-width: 768px) and (max-width: 900px) {

    /* Điều chỉnh độ rộng cột cho tablet */
    .sources-table .table-row {
        grid-template-columns: 50px 200px minmax(150px, 1fr) minmax(180px, 1.2fr) minmax(130px, 0.8fr) minmax(120px, 0.7fr);
        gap: 0.75rem;
    }

    /* Rút gọn URL với ellipsis */
    .sources-table .source-url {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Giảm padding để tiết kiệm không gian */
    .sources-table .table-row {
        padding: 0.6rem 0;
    }

    /* Giảm gap của actions */
    .sources-table .actions {
        gap: 0.5rem;
    }
}