:root {
    --blue: #061f3d;
    --blue-2: #0c335f;
    --green: #18b388;
    --green-2: #0d9d7a;
    --gray: #f3f7f9;
    --line: #d9e6ec;
    --text: #10223b;
    --muted: #64748b;
    --danger: #d94646;
    --warn: #f2c94c;
    --surface: #ffffff;
    --surface-soft: #f8fbfc;
    --shadow: 0 14px 34px rgba(6, 31, 61, .09);
}

* { box-sizing: border-box; }

html {
    width: 100%;
    overflow-x: hidden;
}

body {
    margin: 0;
    width: 100%;
    min-width: 0;
    overflow-x: hidden;
    font-family: "Segoe UI", Arial, Helvetica, sans-serif;
    background:
        linear-gradient(180deg, #ffffff 0, var(--gray) 260px),
        var(--gray);
    color: var(--text);
    font-size: 15px;
    line-height: 1.45;
}

.hidden { display: none !important; }

#appView {
    width: 100%;
    min-width: 0;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card, .card, .table-card, dialog {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.auth-card {
    width: min(420px, 100%);
    padding: 28px;
    border-top: 4px solid var(--green);
}

.auth-card h1, .brand {
    color: var(--blue);
    letter-spacing: .01em;
}

.auth-card h1 span, .brand span { color: var(--green); }

.auth-card h1 {
    display: flex;
    align-items: center;
    gap: 12px;
}

.auth-card h1 img {
    width: min(210px, 70%);
    height: auto;
    display: block;
}

label {
    display: grid;
    gap: 6px;
    margin-bottom: 12px;
    font-weight: 700;
}

input, select, textarea, button {
    font: inherit;
}

input, select, textarea {
    width: 100%;
    border: 1px solid #cadbe3;
    border-radius: 8px;
    padding: 11px 12px;
    background: #fff;
    color: var(--text);
}

input:focus, select:focus, textarea:focus {
    outline: 0;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(24, 179, 136, .16);
}

button {
    border: 0;
    border-radius: 8px;
    padding: 10px 16px;
    background: var(--blue);
    color: #fff;
    cursor: pointer;
    white-space: nowrap;
    font-weight: 700;
    box-shadow: 0 7px 18px rgba(6, 31, 61, .14);
}

button:hover { background: var(--blue-2); }
button:disabled {
    cursor: not-allowed;
    opacity: .45;
}
button.secondary, button.ghost {
    background: #fff;
    color: var(--blue);
    border: 1px solid var(--line);
    box-shadow: none;
}
button.danger { background: var(--danger); }

.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 18px 28px;
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 4px 22px rgba(6, 31, 61, .06);
    position: sticky;
    top: 0;
    z-index: 10;
    width: 100%;
    min-width: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 21px;
    flex: 0 0 auto;
}

.brand img {
    width: 128px;
    max-height: 42px;
    display: block;
}

nav {
    display: flex;
    gap: 10px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

nav button {
    background: transparent;
    color: var(--blue);
    border: 1px solid transparent;
    padding: 10px 14px;
    min-height: 40px;
    box-shadow: none;
    font-weight: 600;
}

nav button.active {
    border-color: rgba(24, 179, 136, .45);
    color: #fff;
    background: var(--blue);
    box-shadow: inset 0 -3px 0 var(--green);
}

.session-area {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
}

.current-user {
    color: var(--blue);
    font-weight: 700;
    white-space: nowrap;
}

.page {
    padding: 32px;
    width: 100%;
    min-width: 0;
    max-width: 1720px;
    margin: 0 auto;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

h1 { margin: 0 0 16px; font-size: 30px; }
h1, h2 {
    color: var(--blue);
    font-weight: 800;
}
h2 { margin-top: 0; font-size: 19px; }

.toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

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

.dashboard-grid, .cards, .two-col {
    display: grid;
    gap: 22px;
    min-width: 0;
}

.dashboard-grid > *,
.cards > *,
.two-col > *,
.project-layout > *,
.vacation-layout > *,
.time-layout > * {
    min-width: 0;
}

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

.cards {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.two-col {
    grid-template-columns: minmax(0, 1fr) 380px;
}

.card, .table-card {
    padding: 22px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.table-card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.card h2,
.table-card h2 {
    margin-bottom: 16px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

th, td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

tbody tr:hover {
    background: var(--surface-soft);
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin: 12px 0 24px;
}

.stats > div {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.stats strong,
.stats span {
    display: block;
}

.stats strong {
    font-size: 28px;
    color: var(--blue);
    line-height: 1;
}

.stats span {
    margin-top: -8px;
    color: #607184;
}

.deadline-card {
    display: flex;
    flex-direction: column;
}

.deadline-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin: 12px 0 24px;
}

.deadline-stats > div {
    min-height: 72px;
    display: grid;
    align-content: center;
    gap: 4px;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 13px 14px;
}

.deadline-stats strong,
.deadline-stats span {
    display: block;
}

.deadline-stats strong {
    color: var(--blue);
    font-size: 28px;
    line-height: 1;
}

.deadline-stats span {
    color: var(--muted);
    line-height: 1.2;
}

.deadline-list {
    display: grid;
}

.deadline-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.deadline-row:last-child {
    border-bottom: 0;
}

.deadline-row > div {
    min-width: 0;
}

.deadline-row .link {
    overflow-wrap: anywhere;
}

.deadline-row strong {
    color: var(--blue);
    white-space: nowrap;
}

.danger-text {
    color: var(--danger) !important;
}

.metric {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.metric strong {
    color: var(--blue);
}

.metric:last-child {
    border-bottom: 0;
}

.dashboard-task-list {
    display: grid;
}

.dashboard-task {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: start;
    padding: 13px 0;
    border-bottom: 1px solid var(--line);
}

.dashboard-task:last-child {
    border-bottom: 0;
}

.dashboard-task strong,
.dashboard-task span {
    display: block;
    overflow-wrap: anywhere;
}

.dashboard-task .link {
    margin-top: 4px;
}

.dashboard-task small {
    color: var(--muted);
    white-space: nowrap;
    padding-top: 2px;
}

.task-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.task-pager span {
    color: var(--muted);
    font-weight: 700;
    min-width: 48px;
    text-align: center;
}

.arrow-button {
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 50%;
    font-size: 26px;
    line-height: 1;
}

.button-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

th {
    color: var(--muted);
    font-size: 13px;
}

.link {
    color: var(--blue);
    font-weight: 700;
    text-decoration: underline;
    cursor: pointer;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    background: #eaf2f5;
    font-size: 12px;
}

.status-options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.status-options button {
    background: var(--surface-soft);
    color: var(--blue);
    border: 1px solid var(--line);
    padding: 7px 10px;
    box-shadow: none;
}

.status-options button.selected {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}

.task-detail-list {
    display: grid;
    gap: 0;
    margin-bottom: 14px;
}

.task-detail-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
}

.task-detail-item:first-child {
    padding-top: 4px;
}

.task-detail-title {
    font-weight: 700;
    overflow-wrap: anywhere;
}

.task-detail-status {
    min-width: 0;
}

.dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
    box-shadow: 0 0 0 3px rgba(24, 179, 136, .08);
}

.green { background: var(--green); }
.yellow { background: var(--warn); }
.red { background: var(--danger); }
.gray { background: #a8b5c0; }

.progress {
    width: 150px;
    height: 18px;
    border-radius: 999px;
    overflow: hidden;
    background: #dfe8ef;
    box-shadow: inset 0 1px 2px rgba(6, 31, 61, .1);
}

.bar {
    height: 100%;
    min-width: 24px;
    background: var(--green);
    color: #fff;
    font-size: 12px;
    text-align: center;
}

.copy-row {
    display: flex;
    gap: 8px;
}

.copy-row input {
    font-family: Consolas, monospace;
}

.calendar-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.calendar-weekday {
    background: var(--blue);
    color: #fff;
    padding: 10px;
    font-weight: 700;
    text-align: center;
}

.calendar-day {
    min-height: 150px;
    background: var(--surface);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.calendar-day.weekend {
    background: #eef4f7;
}

.calendar-day.outside-month {
    background: var(--surface-soft);
    color: #8392a2;
}

.calendar-day.outside-month.weekend {
    background: #edf1f5;
}

.calendar-day.today {
    box-shadow: inset 0 0 0 2px var(--green);
}

.calendar-date {
    font-weight: 700;
    color: var(--blue);
}

.calendar-event {
    width: 100%;
    border-radius: 6px;
    padding: 6px 8px;
    text-align: left;
    color: var(--text);
    background: #e5eef3;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calendar-event strong,
.calendar-event small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calendar-event strong {
    font-size: 13px;
}

.calendar-event small {
    margin-top: 3px;
    color: #607184;
    font-size: 11px;
    line-height: 1.25;
}

.calendar-event.green { background: #dcf5ed; border-left: 4px solid var(--green); }
.calendar-event.yellow { background: #fff3c4; border-left: 4px solid var(--warn); }
.calendar-event.red { background: #ffe0e0; border-left: 4px solid var(--danger); }
.calendar-event.gray { background: #eef2f5; border-left: 4px solid #a8b5c0; }
.holiday-event { background: #eef2f6; border-left: 4px solid #7b8794; }
.vacation-event { background: #d7f1ec; border-left: 4px solid var(--green); }
.sick-event { background: #ffe7e7; border-left: 4px solid var(--danger); }
.time-event { background: #e4f0ff; border-left: 4px solid var(--blue-2); }

.calendar-more {
    font-size: 12px;
    color: var(--muted);
}

.vacation-layout {
    display: grid;
    grid-template-columns: minmax(260px, 0.8fr) minmax(280px, 1fr);
    gap: 16px;
    align-items: start;
}

.time-layout {
    display: grid;
    grid-template-columns: minmax(260px, .7fr) minmax(320px, 1fr);
    gap: 16px;
    align-items: start;
}

.wide-card {
    grid-column: 1 / -1;
}

.time-status {
    display: grid;
    gap: 5px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    margin-bottom: 14px;
}

.time-status.active {
    border-color: rgba(24, 179, 136, .55);
    background: #dcf5ed;
}

.time-status strong {
    color: var(--blue);
    font-size: 20px;
}

.time-status span {
    color: var(--muted);
}

.time-actions {
    justify-content: flex-start;
}

.time-entry-row,
.absence-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: start;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.time-entry-row:last-child,
.absence-row:last-child {
    border-bottom: 0;
}

.time-entry-row span,
.absence-row span,
.absence-row small {
    display: block;
    color: var(--muted);
    margin-top: 3px;
}

.time-entry-row small {
    color: var(--blue);
    font-weight: 800;
    white-space: nowrap;
}

.editable-time-row .button-row {
    align-items: center;
}

.absence-row {
    grid-template-columns: minmax(0, 1fr);
    border-left: 4px solid var(--green);
    padding-left: 12px;
}

.absence-row.sick {
    border-left-color: var(--danger);
}

.calendar-subhead {
    margin: 22px 0 12px;
}

.calendar-subhead h2 {
    margin-bottom: 4px;
}

.vacation-item {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.vacation-item:last-child {
    border-bottom: 0;
}

.vacation-item span,
.vacation-item small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
}

.compact-buttons {
    flex-wrap: nowrap;
}

.project-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 16px;
}

.comment {
    border-top: 1px solid var(--line);
    padding: 10px 0;
}

::selection {
    background: rgba(24, 179, 136, .24);
}

.muted { color: var(--muted); }
.error { color: var(--danger); margin-top: 10px; }

dialog {
    width: min(760px, calc(100vw - 32px));
    border: 0;
    padding: 0;
}

dialog::backdrop { background: rgba(11, 35, 65, .35); }

#modalForm { padding: 18px; }
#modalBody {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 18px;
    margin-top: 14px;
}

#modalBody label:nth-child(2),
#modalBody label:nth-child(3),
#modalBody label:last-child {
    grid-column: 1 / -1;
}

#modalBody textarea {
    min-height: 96px;
}

.modal-head, .modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.modal-actions {
    justify-content: flex-end;
    margin-top: 16px;
}

@media (max-width: 900px) {
    body { font-size: 14px; }
    .topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
        padding: 12px 14px;
        overflow: visible;
    }
    .brand {
        font-size: 18px;
    }
    .brand img {
        width: 118px;
    }
    nav {
        gap: 8px;
        padding-bottom: 2px;
        width: 100%;
        max-width: 100%;
        flex-wrap: wrap;
        overflow-x: visible;
    }
    nav button {
        padding: 9px 12px;
        min-height: 38px;
        flex: 0 1 auto;
    }
    .session-area {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
    }
    .current-user {
        white-space: normal;
    }
    .dashboard-grid, .two-col, .project-layout, .grid-5, .vacation-layout, .time-layout { grid-template-columns: minmax(0, 1fr); }
    .page {
        padding: 14px;
        max-width: none;
        overflow: hidden;
    }
    .page-head {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
        margin-bottom: 16px;
    }
    h1 {
        font-size: 24px;
        margin-bottom: 6px;
    }
    h2 {
        font-size: 17px;
    }
    .card, .table-card { padding: 16px; }
    .table-card table {
        min-width: 620px;
    }
    .copy-row { flex-direction: column; }
    .stats { grid-template-columns: 1fr; }
    .stats span {
        margin-top: 4px;
    }
    .deadline-stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }
    .deadline-stats > div {
        min-height: 64px;
        padding: 10px;
    }
    .deadline-stats strong {
        font-size: 24px;
    }
    .deadline-row {
        grid-template-columns: minmax(0, 1fr);
        gap: 4px;
        align-items: start;
    }
    .deadline-row strong {
        padding-left: 18px;
    }
    .dashboard-task {
        grid-template-columns: minmax(0, 1fr);
        gap: 5px;
    }
    .dashboard-task small {
        white-space: normal;
    }
    .button-row {
        justify-content: flex-start;
        width: 100%;
    }
    .button-row button {
        flex: 1 1 auto;
    }
    .vacation-item {
        flex-direction: column;
    }
    .compact-buttons {
        flex-wrap: wrap;
    }
    #modalBody { grid-template-columns: 1fr; }
    .calendar-grid {
        display: grid;
        grid-template-columns: repeat(7, minmax(0, 1fr));
        gap: 1px;
        background: var(--line);
        border: 1px solid var(--line);
        border-radius: 8px;
        overflow: hidden;
    }
    .calendar-weekday {
        display: block;
        padding: 7px 2px;
        font-size: 12px;
    }
    .calendar-day {
        min-height: 92px;
        border: 0;
        margin-bottom: 0;
        border-radius: 0;
        padding: 5px;
        gap: 4px;
    }
    .calendar-date {
        font-size: 12px;
    }
    .calendar-controls {
        width: 100%;
        justify-content: space-between;
    }
    .calendar-event {
        padding: 4px 5px;
    }
    .calendar-event strong {
        font-size: 10px;
        line-height: 1.15;
        white-space: normal;
    }
    .calendar-event small {
        display: none;
    }
    .status-options {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
    }
    .status-options button {
        white-space: normal;
        width: 100%;
    }
    dialog {
        width: calc(100vw - 18px);
    }
    #modalForm {
        padding: 14px;
    }
}

@media (max-width: 560px) {
    .auth-shell {
        padding: 12px;
    }
    .auth-card {
        padding: 20px;
    }
    .page {
        padding: 10px;
    }
    .card, .table-card {
        padding: 14px;
        border-radius: 7px;
    }
    input, select, textarea {
        min-width: 0;
    }
    .topbar {
        padding: 12px 10px;
    }
    nav {
        margin: 0;
        padding-left: 0;
        padding-right: 0;
        gap: 7px;
    }
    button {
        width: auto;
    }
    table {
        min-width: 560px;
    }
    .toolbar {
        gap: 8px;
    }
    .progress {
        width: 100%;
        max-width: 180px;
    }
    .calendar-day {
        min-height: 78px;
        padding: 4px;
    }
    .calendar-controls {
        flex-wrap: wrap;
    }
    #calendarTitle {
        order: -1;
        width: 100%;
        font-size: 17px;
    }
}
