:root {
    --paper: #f3f1e9;
    --surface: #fffefa;
    --ink: #14251e;
    --muted: #66736d;
    --line: #d4d8d1;
    --forest: #075b48;
    --forest-dark: #034536;
    --amber: #f1b83b;
    --coral: #df684f;
    --sky: #58a9d6;
    --lilac: #8b77bd;
    --danger: #a53b32;
    --shadow: 0 12px 32px rgba(20, 37, 30, 0.09);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    color: var(--ink);
    background-color: var(--paper);
    background-image: linear-gradient(rgba(7, 91, 72, 0.035) 1px, transparent 1px), linear-gradient(90deg, rgba(7, 91, 72, 0.035) 1px, transparent 1px);
    background-size: 32px 32px;
    font-family: "Trebuchet MS", "Segoe UI", sans-serif;
    line-height: 1.5;
}

button, input, select { font: inherit; }

.site-header {
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 12px max(24px, calc((100vw - 1120px) / 2));
    border-bottom: 1px solid var(--line);
    background: rgba(255, 254, 250, 0.96);
    backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-family: Georgia, serif; font-size: 1.25rem; font-weight: bold; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; color: var(--ink); background: var(--amber); border: 1px solid var(--ink); box-shadow: 4px 4px 0 var(--forest); font-family: "Trebuchet MS", sans-serif; font-size: 0.8rem; transform: rotate(-3deg); transition: transform 180ms ease, box-shadow 180ms ease; }
.brand:hover .brand-mark { transform: rotate(3deg) scale(1.04); box-shadow: 2px 5px 0 var(--coral); }
nav { display: flex; align-items: center; gap: 6px; }
nav a { padding: 9px 12px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; }
nav a:hover, nav a[aria-current="page"] { color: var(--forest); border-bottom-color: var(--coral); }
.logout-link { width: 40px; padding-inline: 0; color: var(--danger); text-align: center; font-size: 1.2rem; }

.page-shell { width: min(1120px, calc(100% - 48px)); min-height: calc(100vh - 132px); margin: 0 auto; padding: 48px 0 64px; }
.page-heading { position: relative; margin-bottom: 28px; padding-left: 17px; }
.page-heading::before { content: ""; position: absolute; left: 0; top: 3px; bottom: 2px; width: 6px; background: var(--coral); transform: skewY(-10deg); }
.page-heading h1 { max-width: 760px; margin: 2px 0 0; font-family: Georgia, serif; font-size: clamp(2rem, 5vw, 3.2rem); line-height: 1.08; font-weight: normal; }
.eyebrow { margin: 0; color: var(--forest); font-size: 0.75rem; font-weight: bold; letter-spacing: 0; text-transform: uppercase; }

.notice { margin-bottom: 24px; padding: 13px 16px; border-left: 4px solid; background: var(--surface); box-shadow: var(--shadow); }
.notice-success { border-color: var(--forest); }
.notice-error { border-color: var(--danger); }

.summary { display: grid; grid-template-columns: repeat(2, minmax(0, 220px)); gap: 10px; margin-bottom: 28px; }
.summary div { position: relative; display: flex; flex-direction: column; padding: 18px 20px; overflow: hidden; background: var(--surface); transition: transform 160ms ease; }
.summary div:hover { transform: translateY(-3px) rotate(-0.5deg); }
.summary div::after { content: ""; position: absolute; right: -13px; bottom: -17px; width: 50px; height: 50px; border: 8px solid var(--amber); transform: rotate(18deg); opacity: 0.7; }
.summary div:first-child { color: white; background: var(--forest); }
.summary div:first-child span { color: rgba(255, 255, 255, 0.75); }
.summary div:last-child { border: 1px solid var(--line); }
.summary strong { font-family: Georgia, serif; font-size: 2rem; font-weight: normal; line-height: 1; }
.summary span { margin-top: 6px; color: var(--muted); font-size: 0.84rem; }

.task-list { display: grid; gap: 12px; perspective: 900px; }
.task { --task-color: var(--amber); position: relative; display: flex; align-items: center; justify-content: space-between; gap: 24px; min-height: 126px; padding: 24px 70px 24px 26px; overflow: hidden; border: 1px solid var(--line); border-left: 7px solid var(--task-color); background: var(--surface); box-shadow: var(--shadow); animation: task-arrive 420ms both cubic-bezier(0.2, 0.75, 0.25, 1); transition: transform 160ms ease, box-shadow 160ms ease; }
.task[data-classification="A"] { --task-color: var(--coral); }
.task[data-classification="B"] { --task-color: var(--amber); }
.task[data-classification="C"] { --task-color: var(--sky); }
.task[data-classification="D"] { --task-color: var(--lilac); }
.task:nth-child(2) { animation-delay: 45ms; }
.task:nth-child(3) { animation-delay: 90ms; }
.task:nth-child(4) { animation-delay: 135ms; }
.task:nth-child(5) { animation-delay: 180ms; }
.task:nth-child(n+6) { animation-delay: 220ms; }
.task::after { content: ""; position: absolute; right: -28px; top: -28px; width: 78px; height: 78px; border: 12px solid var(--task-color); transform: rotate(24deg); opacity: 0.16; transition: transform 240ms ease, opacity 240ms ease; }
.task:hover { transform: translateY(-3px) rotateX(0.7deg); box-shadow: 0 16px 36px rgba(20, 37, 30, 0.13); }
.task:hover::after { transform: rotate(36deg) scale(1.12); opacity: 0.28; }
.task h2 { margin: 7px 0 2px; font-family: Georgia, serif; font-size: 1.45rem; }
.task p { margin: 0; color: var(--muted); }
.classification { display: inline-block; padding: 3px 8px; color: var(--ink); border: 1px solid #d19a8d; background: #fbe6e1; font-size: 0.72rem; font-weight: bold; text-transform: uppercase; transform: rotate(-1deg); }
.task[data-classification="B"] .classification { border-color: #d6af56; background: #fff2cd; }
.task[data-classification="C"] .classification { border-color: #75aaca; background: #e1f2fb; }
.task[data-classification="D"] .classification { border-color: #9c8cc2; background: #eee9f8; }

.button { min-height: 44px; padding: 9px 18px; border: 1px solid var(--forest); border-radius: 3px; color: white; background: var(--forest); box-shadow: 3px 3px 0 rgba(20, 37, 30, 0.16); cursor: pointer; text-decoration: none; font-weight: bold; transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease; }
.button:hover { background: var(--forest-dark); }
.button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(20, 37, 30, 0.16); }
.button-secondary { display: inline-block; color: var(--forest); background: transparent; }
.button-secondary:hover { color: white; }
.button-done { display: inline-flex; align-items: center; gap: 8px; min-width: 108px; justify-content: center; }
.button-done span { display: grid; place-items: center; width: 21px; height: 21px; border-radius: 50%; color: var(--forest); background: white; transition: transform 180ms ease; }
.button-done:hover span { transform: rotate(-12deg) scale(1.15); }

.empty-state { padding: 64px 24px; border: 1px solid var(--line); background: var(--surface); text-align: center; }
.empty-state h2 { margin: 8px 0 3px; font-family: Georgia, serif; font-size: 1.6rem; }
.empty-state p { margin: 0 0 22px; color: var(--muted); }
.empty-icon { display: inline-grid; place-items: center; width: 52px; height: 52px; color: white; background: var(--forest); border: 3px solid var(--amber); box-shadow: 5px 5px 0 var(--coral); font-size: 1.5rem; transform: rotate(-4deg); animation: happy-check 2.4s ease-in-out infinite; }

.panel { position: relative; margin-bottom: 20px; padding: 24px; border: 1px solid var(--line); border-top: 4px solid var(--forest); background: var(--surface); box-shadow: var(--shadow); animation: panel-arrive 360ms both ease-out; }
.panel:nth-of-type(even) { border-top-color: var(--coral); animation-delay: 70ms; }
.narrow-panel { max-width: 760px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.section-heading h2 { margin: 2px 0 0; font-family: Georgia, serif; font-size: 1.4rem; }
.count { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--line); color: var(--forest); font-weight: bold; }

.list-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 0 16px; }
.search-field { position: relative; display: block; width: min(100%, 480px); }
.search-field input { min-height: 48px; padding-left: 44px; border-color: #aebbb4; box-shadow: 0 5px 14px rgba(20, 37, 30, 0.06); transition: transform 160ms ease, box-shadow 160ms ease; }
.search-field input:focus { transform: translateY(-1px); box-shadow: 4px 5px 0 rgba(241, 184, 59, 0.42); }
.search-icon { position: absolute; z-index: 1; left: 14px; top: 10px; color: var(--forest); font-size: 1.3rem; line-height: 1; }
.search-count { flex: 0 0 auto; color: var(--muted); font-size: 0.8rem; }
.filter-empty { padding: 34px 18px; color: var(--muted); border: 1px dashed #aebbb4; background: rgba(255, 255, 255, 0.48); text-align: center; }
[hidden] { display: none !important; }

label { display: grid; gap: 6px; color: var(--muted); font-size: 0.78rem; font-weight: bold; }
input, select { width: 100%; min-height: 43px; padding: 8px 10px; color: var(--ink); border: 1px solid #bcc1b9; border-radius: 2px; background: white; }
input:focus, select:focus { outline: 2px solid rgba(30, 91, 66, 0.25); border-color: var(--forest); }
.optional { font-weight: normal; }
.company-form { display: grid; grid-template-columns: 2fr 1fr 1.2fr auto; align-items: end; gap: 14px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 10px; color: var(--muted); border-bottom: 1px solid var(--line); text-align: left; font-size: 0.74rem; text-transform: uppercase; }
th:nth-child(1) { width: 42%; }
th:nth-child(2) { width: 19%; }
th:nth-child(3) { width: 25%; }
th:nth-child(4) { width: 14%; }
td { padding: 10px 0; border-bottom: 1px solid #e6e6df; }
tr:last-child td { border-bottom: 0; }
.table-form { display: grid; grid-template-columns: 42fr 19fr 25fr 14fr; align-items: center; gap: 10px; }
.editable-field { display: block; }
.editable-field > span { display: none; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.icon-button { width: 40px; height: 40px; padding: 0; border: 1px solid var(--forest); border-radius: 2px; color: var(--forest); background: white; cursor: pointer; font-size: 1.1rem; font-weight: bold; transition: transform 130ms ease, background 130ms ease; }
.icon-button:hover { color: white; background: var(--forest); }
.icon-button:hover { transform: rotate(-4deg) scale(1.05); }
.icon-button.danger { color: var(--danger); border-color: #d5aaa6; }
.icon-button.danger:hover { color: white; background: var(--danger); border-color: var(--danger); }

.settings-form { display: grid; grid-template-columns: 1.5fr 1fr auto; align-items: end; gap: 14px; }
.rule-list { display: grid; }
.rule-row { display: grid; grid-template-columns: 1.5fr 1fr auto; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid #e6e6df; }
.rule-row:last-child { border-bottom: 0; }
.days-field { position: relative; }
.days-field input { padding-right: 64px; }
.days-field span:last-child { position: absolute; right: 11px; top: 11px; color: var(--muted); font-weight: normal; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
footer { min-height: 60px; padding: 20px 24px; color: var(--muted); border-top: 1px solid var(--line); text-align: center; font-size: 0.78rem; }

.login-page { min-height: 100vh; background-color: var(--forest); background-image: linear-gradient(rgba(255, 255, 255, 0.055) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.055) 1px, transparent 1px); background-size: 36px 36px; }
.login-shell { width: min(940px, calc(100% - 32px)); min-height: 100vh; display: grid; grid-template-columns: 1.1fr 0.9fr; align-items: center; gap: clamp(36px, 8vw, 96px); margin: 0 auto; padding: 48px 0; }
.login-intro { color: white; }
.login-intro .brand-mark { margin-bottom: 36px; }
.login-intro .eyebrow { color: var(--amber); }
.login-intro h1 { margin: 4px 0 10px; font-family: Georgia, serif; font-size: clamp(3.2rem, 8vw, 5.8rem); line-height: 0.95; font-weight: normal; }
.login-intro p:last-child { max-width: 390px; color: rgba(255, 255, 255, 0.72); font-size: 1.08rem; }
.login-panel { position: relative; padding: clamp(26px, 5vw, 42px); border-top: 6px solid var(--amber); background: var(--surface); box-shadow: 12px 12px 0 rgba(0, 0, 0, 0.2); animation: login-arrive 520ms both cubic-bezier(0.2, 0.75, 0.25, 1); }
.login-panel::after { content: ""; position: absolute; right: 18px; top: -15px; width: 54px; height: 20px; background: rgba(223, 104, 79, 0.78); transform: rotate(4deg); }
.login-panel h2 { margin: 2px 0 28px; font-family: Georgia, serif; font-size: 2rem; font-weight: normal; }
.login-panel .notice { box-shadow: none; }
.login-form { display: grid; gap: 18px; }
.login-form .button { margin-top: 4px; }
.session-note { margin: 20px 0 0; color: var(--muted); font-size: 0.76rem; text-align: center; }

@keyframes task-arrive {
    from { opacity: 0; transform: translateY(18px) rotateX(-3deg); }
    to { opacity: 1; transform: translateY(0) rotateX(0); }
}

@keyframes panel-arrive {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes login-arrive {
    from { opacity: 0; transform: translateY(22px) rotate(1deg); }
    to { opacity: 1; transform: translateY(0) rotate(0); }
}

@keyframes happy-check {
    0%, 100% { transform: rotate(-4deg) translateY(0); }
    50% { transform: rotate(3deg) translateY(-4px); }
}

@media (max-width: 760px) {
    .site-header { position: sticky; z-index: 10; top: 0; align-items: flex-start; flex-direction: column; gap: 6px; padding: 10px 12px 0; box-shadow: 0 2px 12px rgba(20, 37, 30, 0.1); }
    .brand-mark { width: 34px; height: 34px; box-shadow: 3px 3px 0 var(--forest); }
    .brand { font-size: 1.08rem; }
    nav { width: 100%; overflow-x: auto; }
    nav a { flex: 1 0 auto; padding: 8px 9px; text-align: center; white-space: nowrap; }
    .logout-link { flex: 0 0 40px; }
    .page-shell { width: min(100% - 24px, 1120px); padding: 24px 0 40px; }
    .page-heading { margin-bottom: 20px; }
    .page-heading h1 { font-size: 2rem; }
    .summary { grid-template-columns: repeat(2, 1fr); }
    .summary div { padding: 14px; }
    .summary strong { font-size: 1.65rem; }
    .list-toolbar { align-items: stretch; flex-direction: column; gap: 7px; }
    .search-field { width: 100%; }
    .search-count { align-self: flex-end; }
    .task-list { gap: 10px; }
    .task { align-items: stretch; flex-direction: column; gap: 18px; min-height: 0; padding: 18px 46px 18px 16px; }
    .task:hover { transform: none; }
    .task h2 { overflow-wrap: anywhere; font-size: 1.25rem; }
    .task p { font-size: 0.88rem; }
    .task form, .button-done { width: 100%; }
    .company-form, .settings-form, .rule-row { grid-template-columns: 1fr; }
    .panel { padding: 18px 14px; }
    .table-panel { padding: 18px 12px; }
    table, thead, tbody, tr, th, td { display: block; }
    thead { position: absolute; width: 1px; height: 1px; overflow: hidden; }
    tbody { display: grid; gap: 12px; }
    td { padding: 0; border: 0; }
    .table-form { grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px; border: 1px solid var(--line); border-left: 4px solid var(--forest); background: white; box-shadow: 0 7px 18px rgba(20, 37, 30, 0.07); }
    .editable-field:first-of-type { grid-column: 1 / -1; }
    .editable-field > span { display: block; margin-bottom: 4px; }
    .row-actions { grid-column: 1 / -1; justify-content: flex-end; padding-top: 2px; }
    .icon-button { width: 46px; height: 46px; }
    .empty-state { padding: 44px 18px; }
    .login-shell { min-height: 100vh; grid-template-columns: 1fr; align-content: center; gap: 26px; padding: 28px 0; }
    .login-intro .brand-mark { margin-bottom: 22px; }
    .login-intro h1 { font-size: 3.3rem; }
    .login-intro p:last-child { margin-bottom: 0; }
    .login-panel { box-shadow: 7px 7px 0 rgba(0, 0, 0, 0.2); }
}

@media (max-width: 390px) {
    .summary { grid-template-columns: 1fr; }
    .table-form { grid-template-columns: 1fr; }
    .editable-field:first-of-type, .row-actions { grid-column: auto; }
    .row-actions { justify-content: stretch; }
    .icon-button { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}