/* -------- BASE -------- */

*{
    box-sizing:border-box;
}

body{
    margin:0;
    font-family:Tahoma, Verdana, sans-serif;
    background:#2b2b2b;
    color:#cfcfcf;
    font-size:14px;
}

body.overlay-open{
    overflow:hidden;
}

/* -------- TOP BAR -------- */

.topbar{
    position:fixed;
    top:0;
    width:100%;
    background:#1f1f1f;
    border-bottom:2px solid #000;
    z-index:50;
}

.topbar-inner{
    display:flex;
    gap:6px;
    padding:4px;
    align-items:center;
}

.topbar-inner select{
    min-width:0;
}

/* compact logout */
button.ghost{
    width:auto;
    padding:3px 8px;
    font-size:12px;
    background:#333;
    color:#8aff00;
    border:1px solid #000;
}


.item-filter{
    flex:1 1 220px;
    min-width:140px;
    height:32px;
    padding:6px 8px;
}

.type-order:disabled{
    color:#777;
    background:#1b1b1b;
    cursor:not-allowed;
}

/* -------- PAGE -------- */

.page{
    padding:40px 6px 60px;
}

/* -------- INPUTS -------- */

input, textarea, select{
    background:#111;
    color:#00ff66;
    border:1px solid #000;
    padding:7px;
    font-size:14px;
}

input:focus, textarea:focus, select:focus{
    outline:none;
    border-color:#ff9900;
}

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

.field{
    display:flex;
    flex-direction:column;
    gap:4px;
    margin-bottom:8px;
}

/* -------- BUTTON -------- */

button{
    background:#2c2c2c;
    color:#ff9900;
    border:1px solid #000;
    padding:7px;
    cursor:pointer;
}

button:hover{
    background:#3a3a3a;
}

button:disabled{
    opacity:.55;
    cursor:default;
}

/* -------- TODO LIST -------- */

.list{
    display:flex;
    flex-direction:column;
    gap:4px;
}

.todo{
    background:#1a1a1a;
    border:1px solid #000;
    padding:4px;
    cursor:pointer;
}

.todo:hover{
    background:#202020;
}

.todo-main{
    display:flex;
    gap:6px;
    align-items:center;
}

.todo-title{
    color:#00ff66;
    flex:1;
    min-width:0;
    overflow-wrap:anywhere;
}

.topic-label{
    display:inline-block;
    padding:2px 6px;
    border-radius:4px;
    background:#333;
    color:#fff;
    line-height:1.25;
}

.todo-details{
    margin-top:4px;
    padding:4px 24px 2px;
    font-size:12px;
    color:#ffcc66;
    overflow-wrap:anywhere;
}


.edit-btn{
    flex:0 0 auto;
    min-height:30px;
    padding:4px 9px;
}

/* -------- FLOAT BUTTON -------- */

.fab{
    position:fixed;
    left:8px;
    bottom:8px;
    width:46px;
    height:46px;
    border-radius:0;
    font-size:22px;
    background:#111;
    color:#00ff66;
    border:1px solid #000;
    z-index:60;
}

.fab:hover{
    color:#ff9900;
}

/* -------- OVERLAY -------- */

.overlay{
    position:fixed;
    inset:0;
    background:rgba(0,0,0,.85);
    align-items:center;
    justify-content:center;
    z-index:999;
    padding:10px;
}

.overlay-inner{
    background:#1a1a1a;
    border:2px solid #000;
    width:100%;
    max-width:520px;
    max-height:calc(100dvh - 20px);
    display:flex;
    flex-direction:column;
}

.overlay-header{
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:8px;
    padding:10px;
    color:#ff9900;
    border-bottom:1px solid #000;
}

.overlay-header h2{
    margin:0;
    font-size:18px;
}

.overlay-body{
    overflow-y:auto;
    padding:10px;
    -webkit-overflow-scrolling:touch;
}

.overlay-actions{
    display:flex;
    justify-content:flex-end;
    gap:8px;
    padding:10px;
    border-top:1px solid #000;
    background:#1a1a1a;
}

.action-btn{
    min-width:88px;
    min-height:42px;
}

/* -------- LOGIN / CARDS -------- */

.card{
    background:#1a1a1a;
    border:2px solid #000;
    padding:10px;
    width:260px;
}

.center{
    height:100vh;
    display:flex;
    justify-content:center;
    align-items:center;
}

/* -------- GRID -------- */

.grid2{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:8px;
}

/* -------- LINKS -------- */

a{
    color:#00ff66;
    text-decoration:none;
}

a:hover{
    color:#ff9900;
}

/* -------- ERROR TEXT -------- */

.error, .msg{
    color:#ff4444;
    font-size:12px;
}

/* -------- PHONE -------- */

@media (max-width:600px){
    .topbar-inner{
        flex-wrap:wrap;
    }

    .item-filter{
        flex:1 1 100%;
        width:100%;
        min-height:40px;
        font-size:16px;
    }

    .topbar-inner select{
        flex:1 1 calc(50% - 3px);
        font-size:13px;
    }

    .topbar-inner .ghost{
        margin-left:auto;
    }

    .page{
        padding-top:118px;
    }

    .overlay{
        padding:0;
        align-items:stretch;
    }

    .overlay-inner{
        max-width:none;
        max-height:100dvh;
        height:100dvh;
        border:0;
    }

    .grid2{
        grid-template-columns:1fr;
        gap:0;
    }

    .overlay input,
    .overlay textarea,
    .overlay select{
        width:100%;
        font-size:16px; /* avoids iOS input zoom */
        min-height:44px;
    }

    .overlay textarea{
        min-height:130px;
    }

    .overlay-actions{
        padding-bottom:max(10px, env(safe-area-inset-bottom));
    }

    .action-btn{
        flex:1;
        min-height:46px;
        font-size:16px;
    }
}

/* -------- TOP CHECKBOX FILTERS -------- */

.multi-filter{
    position:relative;
    min-width:130px;
}

.multi-filter-btn{
    width:100%;
    min-height:32px;
    padding:6px 28px 6px 8px;
    text-align:left;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
    background:#111;
    color:#00ff66;
    border:1px solid #000;
}

.multi-filter-btn::after{
    content:"▾";
    position:absolute;
    right:9px;
    top:50%;
    transform:translateY(-50%);
    pointer-events:none;
}

.multi-filter-menu{
    position:absolute;
    top:calc(100% + 2px);
    left:0;
    min-width:100%;
    max-height:300px;
    overflow-y:auto;
    background:#111;
    border:1px solid #000;
    z-index:100;
    box-shadow:0 4px 12px rgba(0,0,0,.45);
    -webkit-overflow-scrolling:touch;
}

.filter-option{
    display:flex;
    align-items:center;
    gap:8px;
    min-height:40px;
    padding:7px 9px;
    color:#00ff66;
    cursor:pointer;
    white-space:nowrap;
}

.filter-option + .filter-option{
    border-top:1px solid #262626;
}

.filter-option-all{
    color:#ffcc66;
    font-weight:bold;
    border-bottom:1px solid #444;
}

.filter-option input{
    width:18px;
    height:18px;
    margin:0;
    flex:0 0 auto;
}

.filter-empty{
    padding:9px;
    color:#cfcfcf;
    white-space:nowrap;
}

@media (max-width:600px){
    .multi-filter{
        flex:1 1 calc(50% - 3px);
        min-width:0;
    }

    .multi-filter-btn{
        min-height:38px;
        font-size:13px;
    }

    .multi-filter-menu{
        min-width:160px;
        max-width:calc(100vw - 12px);
    }

    .filter-option{
        min-height:44px;
        font-size:16px;
    }
}

/* -------- EDIT PRIORITY / DELETE -------- */

.prio-adjust{
    display:grid;
    grid-template-columns:repeat(4, minmax(0, 1fr));
    gap:5px;
    margin-top:5px;
}

.prio-adjust-btn{
    min-height:38px;
    padding:6px 4px;
    font-size:13px;
    white-space:nowrap;
}

.overlay-actions-spacer{
    flex:1;
}

.delete-btn{
    background:#421717;
    color:#ff7777;
    border-color:#000;
}

.delete-btn:hover{
    background:#5a1d1d;
}

@media (max-width:600px){
    .prio-adjust-btn{
        min-height:44px;
        font-size:15px;
    }

    .overlay-actions{
        flex-wrap:wrap;
    }

    .overlay-actions-spacer{
        display:none;
    }

    .overlay-actions .delete-btn{
        flex:1 1 100%;
        order:3;
    }
}

/* -------- PRIORITY GROUPS -------- */

.prio-group-divider{
    height:1px;
    background:#666;
    margin:8px 2px 4px;
}

/* -------- FLOATING APP MENU -------- */

.floating-menu-wrap{
    position:fixed;
    right:8px;
    bottom:8px;
    z-index:70;
}

.menu-fab{
    position:static;
    left:auto;
    bottom:auto;
}

.floating-menu{
    position:absolute;
    right:0;
    bottom:54px;
    min-width:180px;
    background:#111;
    border:1px solid #000;
    box-shadow:0 4px 14px rgba(0,0,0,.55);
}

.floating-menu-item{
    display:block;
    width:100%;
    padding:12px 14px;
    border:0;
    border-bottom:1px solid #292929;
    background:#111;
    color:#00ff66;
    text-align:left;
    font:inherit;
    text-decoration:none;
    cursor:pointer;
}

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

.floating-menu-item:hover{
    background:#2c2c2c;
    color:#ff9900;
}

/* -------- TODO TYPES EDITOR -------- */

.types-overlay-inner{
    max-width:720px;
}

.type-editor-head{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:10px;
    margin-bottom:10px;
    color:#ffcc66;
}

.type-editor-list{
    display:flex;
    flex-direction:column;
    gap:8px;
}

.type-editor-row{
    border:1px solid #000;
    background:#202020;
    padding:8px;
}

.type-editor-id{
    margin-bottom:6px;
    color:#ffcc66;
    font-size:12px;
}

.type-editor-fields{
    display:grid;
    grid-template-columns:minmax(0, 2fr) minmax(90px, .7fr) minmax(100px, .8fr) minmax(170px, 1.1fr);
    gap:8px;
}

.type-editor-fields label{
    display:flex;
    flex-direction:column;
    gap:3px;
    font-size:12px;
}

.type-editor-fields input{
    width:100%;
}

.type-color-control{
    display:flex;
    align-items:center;
    gap:6px;
    min-height:36px;
}

.type-color-control .type-color{
    width:48px;
    min-width:48px;
    height:36px;
    padding:2px;
    cursor:pointer;
}

.type-color-value{
    min-width:64px;
    font-size:12px;
    overflow-wrap:anywhere;
}

.type-delete-x{
    width:34px;
    min-width:34px;
    height:34px;
    padding:0;
    font-size:22px;
    line-height:1;
}

.type-editor-actions{
    display:flex;
    justify-content:flex-end;
    gap:6px;
    margin-top:8px;
}

@media (max-width:600px){
    .floating-menu{
        min-width:210px;
    }

    .floating-menu-item{
        min-height:48px;
        font-size:16px;
    }

    .type-editor-fields{
        grid-template-columns:1fr 1fr;
    }

    .type-editor-fields label:first-child{
        grid-column:1 / -1;
    }

    .type-editor-fields label:last-child{
        grid-column:1 / -1;
    }

    .type-editor-actions button{
        min-height:44px;
        flex:1;
    }
}


/* -------- AUTOSAVE / SPECIAL FUNCTIONS -------- */

.type-save-status{
    margin-left:8px;
    color:#8aff00;
    font-size:11px;
}

.special-overlay-inner{
    max-width:560px;
}

.special-functions-list{
    display:flex;
    flex-direction:column;
    gap:10px;
}

.special-function-row{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:12px;
    padding:12px;
    border:1px solid #000;
    background:#202020;
}

.special-function-help{
    margin-top:4px;
    color:#aaa;
    font-size:12px;
}

.danger-action{
    min-width:90px;
    min-height:42px;
    background:#421717;
    color:#ff7777;
}

@media (max-width:600px){
    .special-function-row{
        align-items:stretch;
        flex-direction:column;
    }

    .danger-action{
        width:100%;
        min-height:46px;
        font-size:16px;
    }
}

/* -------- ADMIN PASSWORD -------- */

.admin-overlay-inner{
    max-width:460px;
}

.admin-user-line{
    margin-bottom:12px;
    color:#ffcc66;
}

.admin-success{
    color:#8aff00;
    font-size:12px;
}

/* -------- LARGER TEXT + TOP ACTION BUTTONS -------- */

body{
    font-size:16px;
}

input, textarea, select, button{
    font-size:16px;
}

.todo-details{
    font-size:14px;
}

.error, .msg,
.type-editor-id,
.type-editor-fields label,
.type-color-value,
.special-function-help,
.admin-success{
    font-size:14px;
}

.top-action-btn{
    flex:0 0 40px;
    width:40px;
    height:36px;
    min-height:36px;
    padding:0;
    font-size:22px;
    line-height:1;
    background:#111;
    color:#00ff66;
    border:1px solid #000;
}

.top-action-btn:hover{
    color:#ff9900;
}

.top-menu-wrap{
    position:relative;
    flex:0 0 auto;
}

.top-menu-wrap .floating-menu{
    top:calc(100% + 2px);
    right:0;
    bottom:auto;
}

.page{
    padding-top:48px;
}

@media (max-width:600px){
    .multi-filter{
        flex:1 1 calc(50% - 50px);
    }

    .multi-filter-btn{
        font-size:15px;
    }

    .top-action-btn{
        flex:0 0 44px;
        width:44px;
        height:40px;
        min-height:40px;
        font-size:24px;
    }

    .page{
        padding-top:122px;
    }
}


/* -------- VIEW MODE + SETTINGS -------- */

.view-mode-toggle{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:16px;
}

.switch-control{
    position:relative;
    display:inline-block;
    width:46px;
    height:26px;
    flex:0 0 46px;
}

.switch-control input{
    position:absolute;
    opacity:0;
    width:1px;
    height:1px;
}

.switch-slider{
    position:absolute;
    inset:0;
    background:#333;
    border:1px solid #000;
    cursor:pointer;
}

.switch-slider::before{
    content:"";
    position:absolute;
    width:20px;
    height:20px;
    left:2px;
    top:2px;
    background:#cfcfcf;
    transition:transform .15s ease;
}

.switch-control input:checked + .switch-slider{
    background:#245c2d;
}

.switch-control input:checked + .switch-slider::before{
    transform:translateX(20px);
    background:#8aff00;
}

.settings-overlay-inner{
    max-width:460px;
}

.settings-help{
    margin:4px 0 0;
    color:#aaa;
    font-size:14px;
}

.topic-group{
    display:grid;
    grid-template-columns:52px minmax(0, 1fr);
    gap:8px;
    margin-bottom:14px;
    align-items:stretch;
}

.topic-group + .topic-group{
    border-top:1px solid #666;
    padding-top:10px;
}

.topic-group-heading{
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:space-between;
    gap:8px;
    padding:8px 4px;
    color:#ffcc66;
    font-weight:bold;
    cursor:pointer;
    border-radius:6px;
    min-height:100%;
}

.topic-group-label{
    display:flex;
    align-items:center;
    justify-content:center;
    flex:1;
    width:100%;
    padding:8px 4px;
    background:#333;
    color:#fff;
    border-radius:4px;
    writing-mode:vertical-rl;
    transform:rotate(180deg);
    text-orientation:mixed;
    overflow-wrap:anywhere;
}

.topic-group-count{
    color:#aaa;
    font-size:13px;
    white-space:nowrap;
}

.topic-group-items{
    display:flex;
    flex-direction:column;
    gap:4px;
    min-width:0;
}

.topic-group-heading:hover,
.topic-group-heading:focus-visible{
    background:rgba(255,255,255,0.06);
    outline:none;
}

@media (max-width:600px){
    .topic-group{
        grid-template-columns:44px minmax(0, 1fr);
        gap:6px;
    }

    .topic-group-heading{
        padding:6px 3px;
    }

    .topic-group-label{
        padding:6px 3px;
        font-size:14px;
    }

    .topic-group-count{
        font-size:12px;
    }
}


@media (max-width:600px){
    .view-mode-toggle{
        min-height:52px;
    }

    .switch-control{
        width:50px;
        height:30px;
        flex-basis:50px;
    }

    .switch-slider::before{
        width:24px;
        height:24px;
    }

    .switch-control input:checked + .switch-slider::before{
        transform:translateX(20px);
    }
}

/* Mobile toolbar stability: keep + and hamburger together on one row. */
.top-actions,
.toolbar-actions,
.header-actions {
    display: flex;
    flex-wrap: nowrap;
    flex: 0 0 auto;
    gap: 0.45rem;
    align-items: center;
}

#addTodoBtn,
#menuBtn,
#hamburgerBtn,
#hamburgerMenuBtn {
    flex: 0 0 auto;
    white-space: nowrap;
}

@media (max-width: 640px) {
    .top-controls,
    .filters,
    .filter-row,
    .toolbar {
        align-items: center;
    }

    .top-actions,
    .toolbar-actions,
    .header-actions {
        flex-wrap: nowrap !important;
        width: auto;
        margin-left: auto;
    }
}

#addTypeBtn { flex: 0 0 auto; min-width: 2.75rem; }
#settingsMenuItem { flex: 0 0 auto; min-width: 2.75rem; }

/* -------- MOBILE TOPBAR: FIXED ACTION GROUP -------- */
.top-action-group{
    display:flex;
    flex:0 0 auto;
    flex-wrap:nowrap;
    gap:6px;
    align-items:center;
    margin-left:auto;
}

@media (max-width:600px){
    .topbar-inner{
        display:grid;
        grid-template-columns:minmax(0, 1fr) minmax(0, 1fr) auto;
        gap:6px;
        align-items:center;
    }

    .item-filter{
        grid-column:1 / -1;
        width:100%;
        min-width:0;
        flex:none;
    }

    #topicFilter,
    #prioFilter{
        min-width:0;
        width:100%;
        flex:none;
    }

    .top-action-group{
        grid-column:3;
        display:flex;
        flex-wrap:nowrap;
        gap:6px;
        width:max-content;
        margin-left:0;
    }

    .top-action-group .top-action-btn,
    .top-action-group .top-menu-wrap{
        flex:0 0 auto;
    }

    .top-menu-wrap{
        width:44px;
    }

    .page{
        padding-top:94px;
    }
}


/* Desktop-only inline todo priority controls */
.todo-actions{
    display:flex;
    align-items:center;
    gap:4px;
    flex:0 0 auto;
}

.prio-step-btn{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    min-width:30px;
    min-height:30px;
    padding:3px 7px;
    font-size:18px;
    line-height:1;
}

.edit-btn{
    min-width:34px;
    font-size:18px;
    line-height:1;
}

@media (max-width: 768px){
    .prio-step-btn{
        display:none !important;
    }
}

/* Compact desktop priority arrows: two half-height buttons beside Edit. */
.prio-arrow-stack {
  display: inline-flex;
  flex-direction: column;
  align-self: stretch;
  width: 1.8rem;
  min-width: 1.8rem;
  gap: 1px;
}
.prio-arrow-stack .prio-arrow-btn {
  flex: 1 1 50%;
  min-height: 0;
  height: 50%;
  padding: 0 0.2rem;
  line-height: 1;
  font-size: 0.68rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
@media (max-width: 768px) {
  .prio-arrow-stack { display: none !important; }
}

.bulk-add-section {
  margin-top: 1rem;
  border: 1px solid var(--border, #444);
  border-radius: 0.6rem;
  overflow: hidden;
}
.bulk-add-section > summary {
  cursor: pointer;
  padding: 0.8rem 0.9rem;
  font-weight: 600;
  user-select: none;
}
.bulk-add-section[open] > summary {
  border-bottom: 1px solid var(--border, #444);
}
.bulk-add-field {
  padding: 0.9rem;
}
.bulk-add-field textarea {
  width: 100%;
  min-height: 8rem;
  resize: vertical;
}
.bulk-add-field .hint {
  margin-top: 0.45rem;
  opacity: 0.75;
  font-size: 0.9em;
}

.topic-group-deleted.is-collapsed .topic-group-items {
  display: none;
}
.topic-group-deleted {
  opacity: 0.82;
}

.item-filter-wrap {
  position: relative;
  min-width: 0;
  display: flex;
  flex: 1 1 auto;
}
.item-filter-wrap .item-filter {
  width: 100%;
  padding-right: 2rem;
}
.clear-item-filter {
  display: none;
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  padding: 0.1rem 0.35rem;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.75;
}
.clear-item-filter.is-visible {
  display: block;
}
.clear-item-filter:hover {
  opacity: 1;
}

/* Subtle warning highlight for overdue/negative-priority todos. */
.todo.prio-negative {
  background: rgba(255, 140, 0, 0.12);
  box-shadow: inset 3px 0 0 rgba(255, 140, 0, 0.55);
}

/* Search clear button sits immediately after the text field, not at its far edge. */
.item-filter-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.item-filter-wrap .item-filter {
  flex: 1 1 auto;
  min-width: 0;
  padding-right: 0.55rem;
}
.item-filter-wrap .clear-item-filter {
  position: static;
  transform: none;
  flex: 0 0 auto;
  width: 1.65rem;
  height: 1.65rem;
  padding: 0;
  align-items: center;
  justify-content: center;
}
.item-filter-wrap .clear-item-filter.is-visible {
  display: inline-flex;
}

/* Keep vertical topic names on one uninterrupted vertical line. */
.topic-group-label {
  white-space: nowrap !important;
  overflow-wrap: normal !important;
  word-break: keep-all !important;
  flex-shrink: 0;
}
.topic-group-heading {
  min-height: max-content;
}

/* Search clear control: inside the input, immediately after the typed text.
   JS updates --search-text-width as the user types. */
.item-filter-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.item-filter-wrap .item-filter {
  width: 100%;
  padding-right: 2rem;
}
.item-filter-wrap .clear-item-filter {
  position: absolute;
  left: min(calc(var(--search-text-width, 0px) + 0.75rem), calc(100% - 1.9rem));
  right: auto;
  top: 50%;
  transform: translateY(-50%);
  width: 1.45rem;
  height: 1.45rem;
  padding: 0;
  z-index: 2;
}

/* URL overrides: ?prioarrows=1 and ?fontsize=18 */
html { font-size: var(--app-font-size, 16px); }
@media (max-width: 768px) {
  html.force-prio-arrows .prio-arrow-stack { display: inline-flex !important; }
}

/* fontsize URL parameter scales fixed-pixel text used throughout the legacy UI. */
html.custom-font-size body {
  zoom: var(--app-font-scale, 1);
}

/* URL prioarrows override must win over every mobile-only hide rule. */
html.force-prio-arrows .prio-arrow-stack {
  display: inline-flex !important;
  visibility: visible !important;
  flex: 0 0 1.8rem;
}
html.force-prio-arrows .prio-arrow-stack .prio-step-btn,
html.force-prio-arrows .prio-arrow-stack .prio-arrow-btn {
  display: flex !important;
  visibility: visible !important;
}
html.force-prio-arrows .todo-main {
  width: 100%;
  min-width: 0;
}
html.force-prio-arrows .todo-title {
  min-width: 0;
  overflow-wrap: anywhere;
}
.todo, .todo-main {
  max-width: 100%;
  box-sizing: border-box;
}

.remember-login{display:flex;align-items:center;gap:.45rem;margin:.65rem 0;cursor:pointer}.remember-login input{width:auto;margin:0}
