/* ============================================================
   Tính Ngày Công v4.0 — Modern App UI
   Tối ưu WebView + Mobile + PWA
   ============================================================ */

:root {
    --primary: #e91e8c;
    --primary-dark: #c2166e;
    --primary-light: #ff6ec7;
    --primary-bg: #fff0f8;
    --accent: #ff4081;
    --accent2: #7c3aed;
    --success: #10b981;
    --warning: #f59e0b;
    --text: #1a1a2e;
    --text-muted: #64748b;
    --card: #ffffff;
    --border: #fce7f3;
    --shadow: rgba(233, 30, 140, 0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body {
    background: linear-gradient(160deg, #fff0f8 0%, #fce7f3 60%, #f3e8ff 100%);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    min-height: 100vh;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ============ APP WRAPPER ============ */
.app-container {
    display: flex;
    justify-content: center;
    padding: 0 0 20px;
}

.container {
    width: 100%;
    max-width: 480px;
    padding: 0;
}

/* ============ HEADER (h1) ============ */
h1 {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent2) 100%);
    color: white;
    text-align: center;
    font-size: 1.4rem;
    font-weight: 800;
    padding: 20px 20px 18px;
    margin: 0;
    letter-spacing: -0.3px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 20px var(--shadow);
}

/* ============ TẾT COUNTDOWN ============ */
.days-to-tet {
    background: linear-gradient(135deg, #ff4081, #e91e8c);
    color: white;
    margin: 14px 14px 0;
    border-radius: 16px;
    padding: 14px 18px;
    text-align: center;
    font-size: .95rem;
    box-shadow: 0 4px 15px rgba(233, 30, 140, .3);
    animation: softPulse 3s ease-in-out infinite;
}

.days-to-tet strong { font-size: 1.1rem; }

@keyframes softPulse {
    0%, 100% { box-shadow: 0 4px 15px rgba(233,30,140,.3); }
    50% { box-shadow: 0 6px 25px rgba(233,30,140,.5); }
}

/* ============ FORM CARD ============ */
form {
    background: white;
    margin: 14px;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 2px 20px var(--shadow);
    border: 1px solid var(--border);
}

label {
    display: block;
    font-size: .88rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 7px;
    margin-top: 4px;
}

input[type="date"] {
    width: 100%;
    padding: 14px 16px;
    font-size: 1rem;
    border: 2px solid var(--border);
    border-radius: 12px;
    margin-bottom: 16px;
    background: var(--primary-bg);
    color: var(--text);
    outline: none;
    transition: border-color .2s, box-shadow .2s;
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
}

input[type="date"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(233, 30, 140, .12);
    background: white;
}

/* ============ CHECKBOXES ============ */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-bottom: 20px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--primary-bg);
    border-radius: 12px;
    border: 2px solid var(--border);
    cursor: pointer;
    transition: all .2s;
    font-size: .9rem;
    font-weight: 500;
    margin: 0;
}

.checkbox-group label:active { transform: scale(.98); }

.checkbox-group input[type="checkbox"] {
    width: 22px;
    height: 22px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 6px;
}

/* ============ SUBMIT BUTTON ============ */
button[type="submit"] {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent2) 100%);
    color: white;
    border: none;
    border-radius: 14px;
    font-size: 1.05rem;
    font-weight: 800;
    cursor: pointer;
    letter-spacing: .3px;
    box-shadow: 0 4px 15px rgba(233, 30, 140, .4);
    transition: transform .15s, box-shadow .15s;
    font-family: inherit;
}

button[type="submit"]:active {
    transform: scale(.97);
    box-shadow: 0 2px 8px rgba(233, 30, 140, .3);
}

/* ============ RESULT ============ */
.result {
    background: white;
    margin: 14px;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 2px 20px var(--shadow);
    border: 1px solid var(--border);
    animation: slideUp .35s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.result h3 {
    font-size: .85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--primary);
    margin-bottom: 16px;
}

.result-main {
    text-align: center;
    padding: 20px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.result-main strong {
    display: block;
    font-size: .85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 500;
}

.total-days {
    font-size: 4rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
    display: inline-block;
}

/* "ngày" text after total-days */
.result-main > :not(strong):not(.total-days) {
    font-size: 1rem;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

.result-detail {
    font-size: .85rem;
    color: var(--text-muted);
    background: var(--primary-bg);
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    line-height: 1.9;
}

.result-detail p { margin: 0; }

.result-detail strong { color: var(--text); }

/* ============ STATS GRID ============ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 9px;
    margin: 16px 0;
}

.stat-item {
    background: var(--primary-bg);
    border-radius: 14px;
    padding: 14px 8px;
    text-align: center;
    border: 1.5px solid var(--border);
}

.stat-label {
    font-size: .73rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 900;
    color: var(--primary);
    line-height: 1;
}

.stat-sub {
    font-size: .68rem;
    color: var(--text-muted);
    margin-top: 5px;
    line-height: 1.5;
}

/* ============ MONTHLY STATS ============ */
.monthly-stats { margin-top: 16px; }

.monthly-stats h4 {
    font-size: .85rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 10px;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .82rem;
    border-radius: 12px;
    overflow: hidden;
}

.stats-table th {
    background: linear-gradient(135deg, var(--primary), var(--accent2));
    color: white;
    padding: 10px 10px;
    text-align: center;
    font-weight: 700;
    font-size: .78rem;
}

.stats-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    text-align: center;
}

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

.stats-table tr:nth-child(even) td { background: var(--primary-bg); }

.stats-table td:first-child { text-align: left; font-weight: 600; }

.stats-table .highlight {
    color: var(--primary);
    font-weight: 800;
    font-size: .92rem;
}

/* ============ SHARE ACTIONS ============ */
.share-actions { margin-top: 16px; }

.btn-share {
    width: 100%;
    padding: 13px;
    background: linear-gradient(135deg, #f3e8ff, #fce7f3);
    color: var(--accent2);
    border: 2px solid #e9d5ff;
    border-radius: 12px;
    font-size: .9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
}

.btn-share:active { transform: scale(.97); }

/* ============ BUTTON GROUP ============ */
.btn-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin: 14px;
}

.btn-group button {
    padding: 13px 10px;
    border-radius: 12px;
    font-size: .85rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
    font-family: inherit;
    transition: transform .15s, opacity .15s;
}

.btn-group button:active { transform: scale(.97); }

.btn-pdf {
    background: linear-gradient(135deg, #fee2e2, #fecaca);
    color: #991b1b;
    border: 1.5px solid #fca5a5 !important;
}

.btn-excel {
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    color: #065f46;
    border: 1.5px solid #6ee7b7 !important;
}

.btn-tet {
    background: linear-gradient(135deg, var(--primary-bg), #fce7f3);
    color: var(--primary-dark);
    border: 1.5px solid var(--border) !important;
}

.btn-reset {
    background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
    color: #475569;
    border: 1.5px solid #cbd5e1 !important;
}

/* ============ ERROR ============ */
.error {
    background: #fee2e2;
    border: 1px solid #fca5a5;
    color: #991b1b;
    padding: 14px 16px;
    border-radius: 12px;
    font-size: .9rem;
    margin: 0 14px 14px;
}

/* ============ MODAL ============ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1000;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal.show { display: flex; align-items: flex-end; }

.modal-content {
    background: white;
    border-radius: 24px 24px 0 0;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
    animation: slideUpModal .3s ease-out;
}

@keyframes slideUpModal {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 20px 0;
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text);
}

.close-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--primary-bg);
    color: var(--primary);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.modal-body {
    padding: 16px 20px;
    font-size: .9rem;
    color: var(--text-muted);
    line-height: 1.7;
}

.modal-body h4 {
    font-size: .9rem;
    font-weight: 700;
    color: var(--text);
    margin: 12px 0 6px;
}

.modal-body p { margin-bottom: 8px; }

.modal-body ul { margin-left: 16px; margin-bottom: 10px; }

.modal-footer {
    padding: 0 20px 20px;
}

.modal-footer button {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--primary), var(--accent2));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: .95rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}

/* ============ SHARE MODAL ============ */
#shareModalContent {
    background: var(--primary-bg);
    border-radius: 12px;
    padding: 14px;
    margin: 10px 0;
    font-size: .85rem;
    color: var(--primary-dark);
    word-break: break-all;
    font-family: monospace;
    border: 1px solid var(--border);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 380px) {
    h1 { font-size: 1.2rem; }
    .total-days { font-size: 3rem; }
    .stats-grid { gap: 6px; }
    .stat-value { font-size: 1.3rem; }
    .btn-group { gap: 7px; }
    .btn-group button { font-size: .8rem; padding: 11px 8px; }
}

@media (min-width: 500px) {
    form, .result { margin: 14px 20px; }
    .btn-group { margin: 14px 20px; }
    .error { margin: 0 20px 14px; }
    .days-to-tet { margin: 14px 20px 0; }
}

/* ============ ANIMATIONS ============ */
form, .result { animation: fadeIn .3s ease-out; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
