* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Arial, "Malgun Gothic", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background: #f4f6f8;
    color: #1f2933;
}

a { color: #0b5cab; text-decoration: none; }
a:hover { text-decoration: underline; }

.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 28px;
    padding: 14px 28px;
    background: #18212f;
    color: #fff;
}

.brand {
    color: #fff;
    font-weight: 800;
    white-space: nowrap;
    letter-spacing: .02em;
}

.top nav {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.top nav a {
    color: #dce6f2;
    font-size: 14px;
    font-weight: 700;
    padding: 8px 12px;
    border-radius: 6px;
}

.top nav a:hover,
.top nav a.active {
    background: #2f4058;
    color: #fff;
    text-decoration: none;
}

.wrap {
    width: 100%;
    max-width: 1280px;
    margin: 28px auto;
    padding: 0 24px;
}

h1 { font-size: 28px; margin: 0 0 22px; }
h2 { font-size: 19px; margin: 0 0 16px; }

.notice,
.error {
    padding: 12px 14px;
    border-radius: 7px;
    margin: 0 0 18px;
}

.notice { background: #e7f7ee; border: 1px solid #9ad4b0; }
.error { background: #fdecec; border: 1px solid #e39a9a; color: #8b1e1e; }

.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.dashboard-summary { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 18px; }

.card,
form.panel {
    background: #fff;
    border: 1px solid #d7e0ea;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

.card { padding: 18px; }
.metric { font-size: 30px; font-weight: 800; margin-top: 8px; }

.stat-card span {
    display: block;
    color: #66788a;
    font-size: 13px;
    font-weight: 800;
    margin-bottom: 8px;
}

.stat-card strong {
    display: block;
    font-size: 22px;
    line-height: 1.25;
    word-break: keep-all;
}

form.panel {
    padding: 22px;
    margin-bottom: 24px;
}

.link-form { padding: 24px; }

label {
    display: block;
    font-weight: 800;
    margin: 14px 0 7px;
}

.required { color: #c42318; margin-left: 2px; }

input[type=text],
input[type=password],
input[type=url],
textarea,
select {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid #b8c4d1;
    border-radius: 7px;
    font: inherit;
    background: #fff;
}

input:focus,
textarea:focus,
select:focus {
    outline: 3px solid #c7e7ff;
    border-color: #2587c8;
}

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

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

.actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 18px;
}

button,
.btn {
    min-height: 36px;
    border: 0;
    border-radius: 7px;
    background: #0b5cab;
    color: #fff;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
}

button:hover,
.btn:hover { filter: brightness(.96); text-decoration: none; }

.btn.secondary,
button.secondary { background: #58677a; }

.btn.danger,
button.danger { background: #b42318; }

.btn.compact,
button.compact {
    min-height: 30px;
    padding: 6px 10px;
    font-size: 13px;
}

.copy-btn {
    min-height: 28px;
    margin-left: 8px;
    padding: 5px 9px;
    border-radius: 6px;
    font-size: 12px;
    background: #58677a;
    white-space: nowrap;
}

.inline { display: inline; }
.muted { color: #66788a; font-size: 13px; }

.details-panel {
    margin-top: 20px;
    padding: 0;
    border: 1px solid #d7e0ea;
    border-radius: 8px;
    background: #fbfcfe;
}

.details-panel summary {
    cursor: pointer;
    font-weight: 800;
    font-size: 16px;
    padding: 14px 16px;
    list-style-position: inside;
}

.details-panel[open] {
    padding-bottom: 16px;
}

.details-panel[open] summary {
    margin-bottom: 2px;
    border-bottom: 1px solid #e4ebf2;
    background: #f0f4f8;
}

.details-panel .row {
    padding: 0 16px;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    background: #fff;
    border: 1px solid #d7e0ea;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

.data-table {
    min-width: 1120px;
}

th,
td {
    padding: 13px 12px;
    border-bottom: 1px solid #e6edf3;
    text-align: left;
    vertical-align: middle;
    font-size: 14px;
}

th {
    background: #e8eef5;
    color: #1d2b3a;
    font-weight: 800;
    white-space: nowrap;
}

tr:last-child td { border-bottom: 0; }
.data-table tr:hover td { background: #f8fbfd; }

.links-table {
    min-width: 1100px;
}

.links-table td:nth-child(2) { min-width: 200px; max-width: 280px; }
.links-table td:nth-child(3) { min-width: 280px; max-width: 380px; }
.links-table td:nth-child(6) { min-width: 240px; max-width: 330px; }

.short-url-cell {
    white-space: nowrap;
}

.short-url {
    display: inline-block;
    max-width: 270px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
    font-weight: 700;
}

.clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.45;
    max-height: 2.9em;
}

.title-slug {
    display: block;
    margin-top: 5px;
    color: #66788a;
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nowrap { white-space: nowrap; }

.actions-cell {
    white-space: nowrap;
}

.row-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.category-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    max-width: 310px;
}

.filter-panel {
    margin-bottom: 18px;
}

.check-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-weight: 800;
}

.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 10px;
}

.dashboard-filter {
    margin-bottom: 18px;
}

.compare-card {
    margin-bottom: 18px;
}

.compare-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.compare-metrics div {
    padding: 12px;
    border: 1px solid #d7e0ea;
    border-radius: 8px;
    background: #fbfcfe;
}

.compare-metrics span {
    display: block;
    color: #66788a;
    font-size: 13px;
    font-weight: 800;
    margin-bottom: 6px;
}

.compare-metrics strong {
    font-size: 21px;
}

.positive { color: #19723a; }
.negative { color: #b42318; }

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.chart-card {
    min-height: 360px;
}

.chart-card canvas {
    width: 100% !important;
    height: 290px !important;
}

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

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

.chart-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.chart-tabs button {
    min-height: 32px;
    padding: 6px 10px;
    background: #58677a;
    font-size: 13px;
}

.dashboard-lists {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.dashboard-lists ol {
    margin: 0;
    padding-left: 22px;
}

.dashboard-lists li {
    margin: 8px 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    max-width: 180px;
    min-height: 26px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.badge-muted {
    background: #eef2f6;
    color: #617083;
}

.badge-info {
    background: #e7f0ff;
    color: #174a8b;
}

.badge-position {
    background: #edf7f0;
    color: #25643d;
}

.badge-active {
    background: #e6f6ec;
    color: #19723a;
}

.badge-inactive {
    background: #f1f3f5;
    color: #697386;
}

.badge-device {
    text-transform: lowercase;
}

.badge-mobile {
    background: #e7f0ff;
    color: #174a8b;
}

.badge-desktop {
    background: #edf7f0;
    color: #25643d;
}

.badge-tablet {
    background: #fff3d6;
    color: #8a5b00;
}

.badge-bot,
.badge-bot.badge-device {
    background: #fff0e6;
    color: #a33a00;
}

.badge-referrer {
    background: #f0f4f8;
    color: #34475e;
}

.code-badge {
    display: inline-block;
    max-width: 170px;
    padding: 4px 8px;
    border-radius: 6px;
    background: #f4f6f8;
    border: 1px solid #d7e0ea;
    color: #26384c;
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.click-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 30px;
    padding: 5px 10px;
    border-radius: 7px;
    background: #eef6ff;
    color: #0b5cab;
    font-weight: 900;
    white-space: nowrap;
}

.click-log-table {
    min-width: 1040px;
}

.click-log-table td:nth-child(2) {
    min-width: 220px;
    max-width: 340px;
}

.click-log-table td:nth-child(7) {
    min-width: 250px;
    max-width: 380px;
}

.log-detail summary {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 6px 10px;
    border-radius: 6px;
    background: #58677a;
    color: #fff;
    font-size: 13px;
    font-weight: 800;
}

.log-detail[open] summary {
    margin-bottom: 10px;
}

.log-detail dl {
    display: grid;
    grid-template-columns: 90px minmax(0, 1fr);
    gap: 7px 10px;
    margin: 0;
    padding: 12px;
    border: 1px solid #d7e0ea;
    border-radius: 8px;
    background: #fbfcfe;
}

.log-detail dt {
    color: #617083;
    font-weight: 800;
}

.log-detail dd {
    margin: 0;
    min-width: 0;
}

.long-text {
    max-width: 260px;
    overflow-wrap: anywhere;
    word-break: break-word;
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
    line-height: 1.45;
}

.bar { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.bar-label { width: 120px; font-size: 13px; }
.bar-track { flex: 1; height: 22px; background: #e6edf3; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: #0b5cab; min-width: 2px; }
.bar-value { width: 60px; text-align: right; font-size: 13px; }

.login {
    max-width: 440px;
    margin: 80px auto;
}

.mobile-card-list {
    display: none;
}

@media (max-width: 900px) {
    .top {
        align-items: flex-start;
        flex-direction: column;
        padding: 14px 18px;
    }

    .top nav {
        gap: 8px;
    }

    .wrap {
        max-width: none;
        margin: 20px auto;
        padding: 0 14px;
    }

    form.panel,
    .link-form {
        padding: 18px;
    }

    .dashboard-grid,
    .dashboard-lists {
        grid-template-columns: 1fr;
    }

    th,
    td {
        font-size: 13px;
        padding: 12px 10px;
    }
}

@media (max-width: 767px) {
    body {
        font-size: 14px;
    }

    .top {
        gap: 12px;
        padding: 14px 14px;
    }

    .brand {
        font-size: 15px;
    }

    .top nav {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .top nav a {
        text-align: center;
        padding: 10px 8px;
    }

    .wrap {
        margin: 16px auto;
        padding: 0 14px;
    }

    h1 {
        font-size: 23px;
        margin-bottom: 16px;
    }

    h2 {
        font-size: 17px;
    }

    .row {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    form.panel,
    .link-form {
        padding: 16px;
        margin-bottom: 18px;
    }

    input[type=text],
    input[type=password],
    input[type=url],
    textarea,
    select {
        min-height: 44px;
        font-size: 16px;
    }

    button,
    .btn {
        min-height: 44px;
        padding: 10px 14px;
    }

    .btn.compact,
    button.compact {
        min-height: 40px;
        padding: 9px 12px;
    }

    .copy-btn {
        min-height: 36px;
        margin-left: 0;
        flex: 0 0 auto;
    }

    .details-panel summary {
        min-height: 46px;
        display: flex;
        align-items: center;
    }

    .table-toolbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .dashboard-summary {
        grid-template-columns: 1fr;
    }

    .chart-head {
        flex-direction: column;
        align-items: flex-start;
    }

    .chart-card {
        min-height: 320px;
        overflow-x: auto;
    }

    .chart-card canvas {
        min-width: 520px;
        height: 260px !important;
    }

    .table-scroll {
        display: none;
    }

    .mobile-card-list {
        display: grid;
        gap: 12px;
    }

    .mobile-card {
        background: #fff;
        border: 1px solid #d7e0ea;
        border-radius: 10px;
        padding: 14px;
        box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
        min-width: 0;
    }

    .mobile-card h3 {
        margin: 0 0 4px;
        font-size: 16px;
        line-height: 1.35;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .mobile-card-head {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 10px;
        min-width: 0;
    }

    .mobile-card-head > div {
        min-width: 0;
    }

    .mobile-url-row {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-top: 12px;
        min-width: 0;
    }

    .mobile-url-row .short-url {
        flex: 1 1 auto;
        max-width: none;
        min-width: 0;
    }

    .mobile-meta {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        margin-top: 12px;
        padding-top: 10px;
        border-top: 1px solid #e6edf3;
    }

    .mobile-meta span {
        color: #66788a;
        font-size: 13px;
        font-weight: 800;
    }

    .mobile-meta strong {
        white-space: nowrap;
    }

    .category-badges {
        max-width: 100%;
        margin-top: 10px;
    }

    .badge {
        max-width: 100%;
    }

    .mobile-card-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-top: 14px;
    }

    .mobile-card-actions .btn,
    .mobile-card-actions form,
    .mobile-card-actions button {
        width: 100%;
    }

    .mobile-log-detail {
        margin-top: 12px;
    }

    .mobile-log-detail summary {
        width: 100%;
        justify-content: center;
        min-height: 42px;
    }

    .log-detail dl {
        grid-template-columns: 1fr;
    }

    .long-text {
        max-width: 100%;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
}

@media (max-width: 480px) {
    .actions {
        flex-direction: column;
        align-items: stretch;
    }

    .actions .btn,
    .actions button,
    .actions a {
        width: 100%;
    }

    .check-inline {
        min-height: 44px;
    }

    .top nav {
        grid-template-columns: 1fr;
    }
}
